Guilds¶
GUILD¶
- class daf.guild.GUILD(snowflake: int | Guild, messages: List[BaseChannelMessage] | None = None, logging: bool | None = False, remove_after: timedelta | datetime | None = None, invite_track: List[str] | None = None, removal_buffer_length: int = 50)¶
The GUILD object represents a server to which messages will be sent.
Changed in version v3.0:
Removed
created_at
property.New
remove_after
property
Changed in version v2.7: Added
invite_track
parameter.- Parameters:
snowflake (Union[int, discord.Guild]) – Discord’s snowflake ID of the guild or discord.Guild object.
messages (Optional[List[Union[TextMESSAGE, VoiceMESSAGE]]]) – Optional list of TextMESSAGE/VoiceMESSAGE objects.
logging (Optional[bool]) – Optional variable dictating whatever to log sent messages inside this guild.
remove_after (Optional[Union[timedelta, datetime]]) –
Deletes the guild after:
timedelta - the specified time difference
datetime - specific date & time
invite_track (Optional[List[str]]) –
Added in version 2.7.
List of invite IDs to be tracked for member join count inside the guild. Bot account only, does not work on user accounts.
Note
Accounts are required to have Manage Channels and Manage Server permissions inside a guild for tracking to fully function. Manage Server is needed for getting information about invite links, Manage Channels is needed to delete the invite from the list if it has been deleted, however tracking still works without it.
Warning
For GUILD to receive events about member joins,
members
intent is required to be True inside theintents
parameters ofdaf.client.ACCOUNT
. This is a privileged intent that also needs to be enabled though Discord’s developer portal for each bot. After it is enabled, you can set it to True .Invites intent is also needed. Enable it by setting
invites
to True inside theintents
parameter ofACCOUNT
.removal_buffer_length (Optional[int]) –
Maximum number of messages to keep in the removed_messages buffer.
Added in version 3.0.
- async initialize(parent: Any, event_ctrl: EventController) None ¶
This function initializes the API related objects and then tries to initialize the MESSAGE objects.
Note
This should NOT be manually called, it is called automatically after adding the message.
- add_message(message: TextMESSAGE | VoiceMESSAGE)¶
Adds a message to the message list.
Warning
To use this method, the guild must already be added to the framework’s shilling list (or initialized).
This is an asynchronous API operation. When returning from this function, the action is not immediately executed.
- Parameters:
message (BaseMESSAGE) – Message object to add.
- Returns:
An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use
await
like so:await method_name()
.- Return type:
Awaitable
- Raises:
TypeError – Raised when the message is not of type the guild allows.
Other – Raised from message.initialize() method.
- generate_invite_log_context(member: Member, invite_id: str) dict ¶
Generates dictionary representing the log of a member joining a guild.
- Parameters:
member (discord.Member) – The member that joined a guild.
- Returns:
{ "id": ID of the invite, "member": { "id": Member ID, "name": Member name } }
- Return type:
- property apiobject: Object¶
Added in version v2.4.
Returns the Discord API wrapper’s object of self.
- generate_log_context() Dict[str, str | int] ¶
Generates a dictionary of the guild’s context, which is then used for logging.
- property messages: List[BaseMESSAGE]¶
Returns all the (initialized) message objects inside the object.
Added in version v2.0.
- property remove_after: datetime | None¶
Returns the timestamp at which object will be removed or None if it will not be removed.
- remove_message(message: BaseMESSAGE) Future ¶
Removes a message from the message list.
This is an asynchronous API operation. When returning from this function, the action is not immediately executed.
Changed in version 3.0: The function is now async.
- Parameters:
message (BaseMESSAGE) – Message object to remove.
- Returns:
An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use
await
like so:await method_name()
.- Return type:
Awaitable
- Raises:
TypeError – Raised when the message is not of type the guild allows.
ValueError – Raised when the message is not present in the list.
- property removed_messages: List[BaseMESSAGE]¶
Returns a list of messages that were removed from server (last
removal_buffer_length
messages).
- update(init_options=None, **kwargs) Future ¶
Added in version v2.0.
Used for changing the initialization parameters, the object was initialized with.
This is an asynchronous API operation. When returning from this function, the action is not immediately executed.
Warning
Upon updating, the internal state of objects get’s reset, meaning you basically have a brand new created object. It also resets the message objects.
- Parameters:
**kwargs (Any) – Custom number of keyword parameters which you want to update, these can be anything that is available during the object creation.
- Returns:
An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use
await
like so:await method_name()
.- Return type:
Awaitable
- Raises:
Union[TypeError, ValueError] – Invalid keyword argument was passed.
USER¶
- class daf.guild.USER(snowflake: int | User, messages: List[DirectMESSAGE] | None = None, logging: bool | None = False, remove_after: timedelta | datetime | None = None, removal_buffer_length: int = 50)¶
The USER object represents a user to whom messages will be sent.
Changed in version v3.0:
Removed
created_at
property.New
remove_after
property
Changed in version v2.7: Added
invite_track
parameter.- Parameters:
snowflake (Union[int, discord.User]) – Discord’s snowflake ID of the user or discord.User object.
messages (Optional[List[DirectMESSAGE]]) – Optional list of DirectMESSAGE objects.
logging (Optional[bool]) – Optional variable dictating whatever to log sent messages inside this guild.
remove_after (Optional[Union[timedelta, datetime]]) –
Deletes the user after:
timedelta - the specified time difference
datetime - specific date & time
removal_buffer_length (Optional[int]) –
Maximum number of messages to keep in the removed_messages buffer.
Added in version 3.0.
- add_message(message: DirectMESSAGE) Future ¶
Adds a message to the message list.
Warning
To use this method, the guild must already be added to the framework’s shilling list (or initialized).
This is an asynchronous API operation. When returning from this function, the action is not immediately executed.
- Parameters:
message (BaseMESSAGE) – Message object to add.
- Returns:
An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use
await
like so:await method_name()
.- Return type:
Awaitable
- Raises:
TypeError – Raised when the message is not of type the guild allows.
Other – Raised from message.initialize() method.
- async initialize(parent: Any, event_ctrl: EventController)¶
This function initializes the API related objects and then tries to initialize the MESSAGE objects.
- property apiobject: Object¶
Added in version v2.4.
Returns the Discord API wrapper’s object of self.
- generate_log_context() Dict[str, str | int] ¶
Generates a dictionary of the guild’s context, which is then used for logging.
- property messages: List[BaseMESSAGE]¶
Returns all the (initialized) message objects inside the object.
Added in version v2.0.
- property remove_after: datetime | None¶
Returns the timestamp at which object will be removed or None if it will not be removed.
- remove_message(message: BaseMESSAGE) Future ¶
Removes a message from the message list.
This is an asynchronous API operation. When returning from this function, the action is not immediately executed.
Changed in version 3.0: The function is now async.
- Parameters:
message (BaseMESSAGE) – Message object to remove.
- Returns:
An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use
await
like so:await method_name()
.- Return type:
Awaitable
- Raises:
TypeError – Raised when the message is not of type the guild allows.
ValueError – Raised when the message is not present in the list.
- property removed_messages: List[BaseMESSAGE]¶
Returns a list of messages that were removed from server (last
removal_buffer_length
messages).
- update(init_options=None, **kwargs) Future ¶
Added in version v2.0.
Used for changing the initialization parameters, the object was initialized with.
This is an asynchronous API operation. When returning from this function, the action is not immediately executed.
Warning
Upon updating, the internal state of objects get’s reset, meaning you basically have a brand new created object. It also resets the message objects.
- Parameters:
**kwargs (Any) – Custom number of keyword parameters which you want to update, these can be anything that is available during the object creation.
- Returns:
An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use
await
like so:await method_name()
.- Return type:
Awaitable
- Raises:
Union[TypeError, ValueError] – Invalid keyword argument was passed.