Functions#
This page contains information about any functions that can be called.
Shilling list modification#
add_object#
- daf.core.add_object(obj: Union[USER, GUILD])
Adds a guild or an user to the daf.
- Parameters:
- Raises:
- ValueError -
The guild/user is already added to the daf.
- TypeError-
The object provided is not supported for addition.
- Other -
Raised in the Guilds (Servers)
.add_message()
method
- daf.core.add_object(obj: Union[DirectMESSAGE, TextMESSAGE, VoiceMESSAGE], snowflake: Union[int, GUILD, USER, dc.Guild, dc.User])#
Adds a message to the daf.
- Parameters:
- obj: Union[DirectMESSAGE, TextMESSAGE, VoiceMESSAGE]
The message object to add into the daf.
- snowflake: Union[int, GUILD, USER, dc.Guild, dc.User]
Which guild/user to add it to (can be snowflake id or a framework _BaseGUILD object or a discord API wrapper object).
- Raises:
- TypeError
guild_id wasn’t provided when adding a message object (to which guild should it add)
- DAFNotFoundError(code=DAF_SNOWFLAKE_NOT_FOUND)
Could not find guild with that id.
- TypeError
The object provided is not supported for addition.
- Other
Raised in the Guilds (Servers)
.add_message()
method
remove_object#
- daf.core.remove_object(snowflake: Union[int, Object, Guild, User, _BaseGUILD, BaseMESSAGE]) None #
Removes an object from the daf.
- Parameters:
snowflake (Union[int, dc.Object, dc.Guild, dc.User, dc.Object, guild.GUILD, guild.USER , message.TextMESSAGE, message.VoiceMESSAGE, message.DirectMESSAGE]) – The GUILD/USER object to remove/snowflake of GUILD/USER or a xMESSAGE object
- Raises:
DAFNotFoundError(code=DAF_SNOWFLAKE_NOT_FOUND) – Could not find guild with that id.
TypeError – Invalid argument.
Getters#
get_client#
- daf.client.get_client() Client #
Returns the CLIENT object used for communicating with Discord.
get_guild_user#
- daf.core.get_guild_user(snowflake: Union[int, Object, Guild, User]) Optional[Union[GUILD, USER]] #
Retrieves the GUILD/USER object that has the
snowflake
ID from the shilling list.- Parameters:
snowflake (Union[int, dc.Object, dc.Guild, dc.User, dc.Object]) – Snowflake ID or discord objects containing snowflake id of the GUILD.
- Raises:
TypeError – Incorrect snowflake type
- Returns:
daf.guild.GUILD
|daf.guild.USER
– The object requested.None – If not guild/user not in the shilling list.
get_shill_list#
- daf.core.get_shill_list() List[Union[GUILD, USER]] #
New in version v2.1.
- Returns:
The shilling list.
- Return type:
List[Union[guild.GUILD, guild.USER]]
get_sql_manager#
Decorators#
data_function#
- daf.dtypes.data_function(fnc: Callable)#
Decorator used to create a framework FunctionCLASS class that wraps the function.
- Parameters:
fnc (Callable) – The function to wrap.
- Returns:
A class for creating wrapper objects is returned. These wrapper objects can be used as a
data
parameter to the Messages objects.- Return type:
FunctionCLASS
import daf, datetime, secret from daf import discord from datetime import timedelta ############################################################################################ # It's VERY IMPORTANT that you use @daf.data_function! ############################################################################################ @daf.data_function def get_data(parameter): l_time = datetime.datetime.now() return f"Parameter: {parameter}\nTimestamp: {l_time.day}.{l_time.month}.{l_time.year} :: {l_time.hour}:{l_time.minute}:{l_time.second}" guilds = [ daf.GUILD( snowflake=123456789, # ID of server (guild) or a discord.Guild object messages=[ # List MESSAGE objects daf.TextMESSAGE( start_period=None, # If None, messages will be send on a fixed period (end period) end_period=timedelta(seconds=15), # If start_period is None, it dictates the fixed sending period, # If start period is defined, it dictates the maximum limit of randomized period data=get_data(123), # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left # or function that returns any of above types(or returns None if you don't have any data to send yet), # where if you pass a function you need to use the daf.FUNCTION decorator on top of it ). channels=[123456789], # List of ids of all the channels you want this message to be sent into mode="send", # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete # the previous message and then send a new one start_in=timedelta(seconds=0) # Start sending now (True) or wait until period ), ], logging=True ## Generate file log of sent messages (and failed attempts) for this server ) ] ############################################################################################ daf.run(token=secret.C_TOKEN, server_list=guilds, is_user=False)
Core controls#
run#
- daf.core.run(token: str, server_list: Optional[List[Union[GUILD, USER]]] = [], is_user: Optional[bool] = False, user_callback: Optional[Callable] = None, server_log_output: Optional[str] = 'History', sql_manager: Optional[LoggerSQL] = None, intents: Optional[Intents] = None, debug: Optional[bool] = True, proxy: Optional[str] = None) None #
Runs the framework and does not return until the framework is stopped (
daf.core.shutdown()
). After stopping, it returns None.Changed in version v2.1: Added
proxy
parameter- Parameters:
token (str) – Discord’s access token for account.
server_list (Optional[List[Union[GUILD, USER]]) – Predefined server list (guild list) to shill.
is_user (Optional[bool]) – Set to True if the token is for an user account.
user_callback (Optional[Callable]) – Users coroutine (task) to run after the framework is run.
server_log_output (Optional[str]) – Path where the server log files will be created.
sql_manager (Optional[LoggerSQL]) – SQL manager object that will save logs into the database.
intents (Optional[discord.Intents]) – Discord Intents object (represents settings to which events it will be listened to).
debug (Optional[bool]) – Print trace message to the console, useful for debugging.
proxy (Optional[str]) – URL of a proxy you want the framework to use.
- Raises:
ModuleNotFoundError – Missing modules for the wanted functionality, install with
pip install discord-advert-framework[optional-group]
.ValueError – Invalid proxy url.
shutdown#
- daf.core.shutdown(loop: Optional[AbstractEventLoop] = None) None #
Stops the framework and any user tasks.
Changed in version v2.1: Made the function non async and shutdown everything.
- Parameters:
loop (Optional[asyncio.AbstractEventLoop]) – The loop everything is running in. Leave empty for default loop.
Debug#
trace#
- daf.tracing.trace(message: str, level: TraceLEVELS = TraceLEVELS.NORMAL, force: bool = False)#
Prints a trace to the console.
This is thread safe.
Changed in version v2.1: Added
force
parameter.- Parameters:
message (str) – Trace message.
level (TraceLEVELS) – Level of the trace. Defaults to TraceLEVELS.NORMAL.
force (bool) – Trace even if tracing is disabled.