Guilds#

GUILD#

class daf.guild.GUILD(snowflake: int | Guild, messages: List[TextMESSAGE | VoiceMESSAGE] | None = None, logging: bool | None = False, remove_after: timedelta | datetime | None = None, invite_track: List[str] | None = None)#

The GUILD object represents a server to which messages will be sent.

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]]) –

    New in version 2.7.

    List of invite IDs to be tracked for member join count inside the guild.

    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.

async initialize(parent: Any, _init=True) 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.

Raises:
  • ValueError – Raised when the guild_id wasn’t found.

  • Other – Raised from .add_message(message_object) 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:

dict

async update(init_options=None, _init=True, **kwargs)#

Used for changing the initialization parameters, the object was initialized with.

New in version v2.0.

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.

Raises:
  • TypeError – Invalid keyword argument was passed.

  • Other – Raised from .initialize() method.

async add_message(message: BaseMESSAGE)#

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).

Parameters:

message (BaseMESSAGE) – Message object to add.

Raises:
  • TypeError – Raised when the message is not of type the guild allows.

  • Other – Raised from message.initialize() method.

property apiobject: Object#

New in version v2.4.

Returns the Discord API wrapper’s object of self.

property created_at: datetime#

New in version v2.1.

Returns the datetime of when the object has been created.

property deleted: bool#

Indicates the status of deletion.

Returns:

  • True – The object is no longer in the framework and should no longer be used.

  • False – Object is in the framework in normal operation.

generate_log_context() Dict[str, str | int]#

Generates a dictionary of the guild’s context, which is then used for logging.

Return type:

Dict[str, Union[str, int]]

property messages: List[BaseMESSAGE]#

Returns all the (initialized) message objects inside the object.

New in version v2.0.

remove_message(message: BaseMESSAGE)#

Removes a message from the message list.

Parameters:

message (BaseMESSAGE) – Message object to remove.

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 snowflake: int#

New in version v2.0.

Returns the discord’s snowflake ID.

USER#

class daf.guild.USER(snowflake: int | User, messages: List[DirectMESSAGE] | None = None, logging: bool | None = False, remove_after: timedelta | datetime | None = None)#

The USER object represents a user to whom messages will be sent.

Changed in version v2.1:

  • Added created_at attribute

  • Added remove_after 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

async initialize(parent: Any)#

This function initializes the API related objects and then tries to initialize the MESSAGE objects.

Raises:
  • ValueError – Raised when the DM could not be created.

  • Other – Raised from .add_message(message_object) method.

async update(init_options=None, _init=True, **kwargs)#

New in version v2.0.

Used for changing the initialization parameters, the object was initialized with.

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.

Raises:
  • TypeError – Invalid keyword argument was passed.

  • Other – Raised from .initialize() method.

async add_message(message: BaseMESSAGE)#

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).

Parameters:

message (BaseMESSAGE) – Message object to add.

Raises:
  • TypeError – Raised when the message is not of type the guild allows.

  • Other – Raised from message.initialize() method.

property apiobject: Object#

New in version v2.4.

Returns the Discord API wrapper’s object of self.

property created_at: datetime#

New in version v2.1.

Returns the datetime of when the object has been created.

property deleted: bool#

Indicates the status of deletion.

Returns:

  • True – The object is no longer in the framework and should no longer be used.

  • False – Object is in the framework in normal operation.

generate_log_context() Dict[str, str | int]#

Generates a dictionary of the guild’s context, which is then used for logging.

Return type:

Dict[str, Union[str, int]]

property messages: List[BaseMESSAGE]#

Returns all the (initialized) message objects inside the object.

New in version v2.0.

remove_message(message: BaseMESSAGE)#

Removes a message from the message list.

Parameters:

message (BaseMESSAGE) – Message object to remove.

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 snowflake: int#

New in version v2.0.

Returns the discord’s snowflake ID.