Messages#

TextMESSAGE#

class daf.message.TextMESSAGE(start_period: timedelta | int | None = None, end_period: int | timedelta = None, data: BaseTextData | list | tuple | set | str | Embed | FILE | _FunctionBaseCLASS = None, channels: list[Union[int, _discord.channel.TextChannel, _discord.threads.Thread]] | AutoCHANNEL = None, mode: Literal['send', 'edit', 'clear-send'] = 'send', start_in: timedelta | datetime | None = None, remove_after: int | timedelta | datetime | None = None, auto_publish: bool = False, period: BaseMessagePeriod = None)#

This class is used for creating objects that represent messages which will be sent to Discord’s TEXT CHANNELS.

Parameters:
  • data (BaseTextData) – The data to be sent. Can be TextMessageData or class inherited from DynamicMessageData

  • channels (Union[list[Union[int, discord.TextChannel, discord.Thread]], daf.message.AutoCHANNEL]) –

    Channels that it will be advertised into (Can be snowflake ID or channel objects from PyCord).

    Changed in version v2.3: Can also be AutoCHANNEL

    Note

    If no channels are left, the message is automatically removed, unless AutoCHANNEL is used.

  • mode (Optional[str]) –

    Parameter that defines how message will be sent to a channel. It can be:

    • ”send” - each period a new message will be sent,

    • ”edit” - each period the previously send message will be edited (if it exists)

    • ”clear-send” - previous message will be deleted and a new one sent.

  • remove_after (Optional[Union[int, timedelta, datetime]]) –

    Deletes the message after:

    • int - provided amounts of successful sends to seperate channels.

    • timedelta - the specified time difference

    • datetime - specific date & time

    Changed in version 2.10: Parameter remove_after of int type will now work at a channel level and it nows means the SUCCESSFUL number of sends into each channel.

  • auto_publish (Optional[bool]) –

    Automatically publish message if sending to an announcement channel. Defaults to False.

    If the channel publish is rate limited, the message will still be sent, but an error will be printed to the console instead of message being published to the follower channels.

    New in version 2.10.

generate_log_context(content: str | None, embed: Embed, files: List[FILE], succeeded_ch: List[TextChannel | Thread], failed_ch: List[Dict[str, Any]]) Dict[str, Any]#

Generates information about the message send attempt that is to be saved into a log.

Parameters:
Returns:

{
    sent_data:
    {
        text: str - The text that was sent,
        embed: Dict[str, Any] - The embed that was sent,
        files: List[str] - List of files that were sent
    },

    channels:
    {
        successful:
        {
            id: int - Snowflake id,
            name: str - Channel name
        },
        failed:
        {
            id: int - Snowflake id,
            name: str - Channel name,
            reason: str - Exception that caused the error
        }
    },
    type: str - The type of the message, this is always TextMESSAGE,
    mode: str - The mode used to send the message (send, edit, clear-send)
}

Return type:

Dict[str, Any]

async initialize(parent: Any, event_ctrl: EventController, channel_getter: Callable)#

This method initializes the implementation specific API objects and checks for the correct channel input context.

Parameters:

parent (daf.guild.GUILD) – The GUILD this message is in

property remove_after: int | datetime | None#

Returns the remaining send counts / date after which the message will be removed from the sending list. If the original type of the remove_after parameter to the message was of type int, this will return the maximum remaining amount of sends from all channels. If all the channels have been removed, this will return the original count remove_after parameter.

update(_init_options: dict | None = None, **kwargs: Any) Future#

New in version v2.0.

Changed in version v3.0: Turned into async api.

This is an asynchronous API operation. When returning from this function, the action is not immediately executed.

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.

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:
  • TypeError – Invalid keyword argument was passed

  • Other – Raised from .initialize() method.

DirectMESSAGE#

class daf.message.DirectMESSAGE(start_period: int | timedelta | None = None, end_period: int | timedelta = None, data: BaseTextData | list | tuple | set | str | Embed | FILE | _FunctionBaseCLASS = None, mode: Literal['send', 'edit', 'clear-send'] | None = 'send', start_in: timedelta | datetime | None = None, remove_after: int | timedelta | datetime | None = None, period: BaseMessagePeriod = None)#

This class is used for creating objects that represent messages which will be sent to user’s private messages.

Deprecated since version v2.1:

  • start_period, end_period - Using int values, use timedelta object instead.

Changed in version v2.7: start_in now accepts datetime object

Parameters:
  • data (BaseTextData) – The data to be sent. Can be TextMessageData or class inherited from DynamicMessageData

  • mode (Optional[str]) –

    Parameter that defines how message will be sent to a channel. It can be:

    • ”send” - each period a new message will be sent,

    • ”edit” - each period the previously send message will be edited (if it exists)

    • ”clear-send” - previous message will be deleted and a new one sent.

  • remove_after (Optional[Union[int, timedelta, datetime]]) –

    Deletes the guild after:

    • int - provided amounts of successful sends

    • timedelta - the specified time difference

    • datetime - specific date & time

generate_log_context(success_context: Dict[str, bool | Exception | None], content: str | None, embed: Embed | None, files: List[FILE]) Dict[str, Any]#

Generates information about the message send attempt that is to be saved into a log.

Parameters:
  • text (str) – The text that was sent.

  • embed (discord.Embed) – The embed that was sent.

  • files (List[FILE]) – List of files that were sent.

  • success_context (Dict[bool, Exception]) – Dictionary containing information about succession of the DM attempt. Contains “success”: bool key and “reason”: Exception key which is only present if “success” is False

Returns:

{
    sent_data:
    {
        text: str - The text that was sent,
        embed: Dict[str, Any] - The embed that was sent,
        files: List[str] - List of files that were sent.
    },
    success_info:
    {
        success: bool - Was sending successful or not,
        reason:  str  - If it was unsuccessful, what was the reason
    },
    type: str - The type of the message, this is always DirectMESSAGE,
    mode: str - The mode used to send the message (send, edit, clear-send)
}

Return type:

Dict[str, Any]

async initialize(parent: Any, event_ctrl: EventController, guild: User)#

The method creates a direct message channel and returns True on success or False on failure

Changed in version v2.1: Renamed user to and changed the type from discord.User to daf.guild.USER

Parameters:

parent (daf.guild.USER) – The USER this message is in

property remove_after: Any#

New in version v3.0.

Returns the remaining send counts / date after which the message will be removed from the sending list.

update(_init_options: dict | None = None, **kwargs) Future#

New in version v2.0.

Changed in version v3.0: Turned into async api.

This is an asynchronous API operation. When returning from this function, the action is not immediately executed.

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.

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:
  • TypeError – Invalid keyword argument was passed

  • Other – Raised from .initialize() method.

VoiceMESSAGE#

class daf.message.VoiceMESSAGE(start_period: int | timedelta | None = None, end_period: int | timedelta = None, data: BaseVoiceData | FILE | list | tuple | set | _FunctionBaseCLASS = None, channels: list[Union[int, _discord.channel.VoiceChannel]] | AutoCHANNEL = None, volume: int | None = 50, start_in: timedelta | datetime | None = None, remove_after: int | timedelta | datetime | None = None, period: BaseMessagePeriod = None)#

This class is used for creating objects that represent messages which will be streamed to voice channels.

Warning

This additionally requires FFMPEG to be installed on your system.

Parameters:
  • data (BaseVoiceData) – The actual data streamed to voice channels. Can be VoiceMessageData or a class inherited from DynamicMessageData.

  • channels (Union[list[Union[int, discord.VoiceChannel]], daf.message.AutoCHANNEL]) – Channels that it will be advertised into (Can be snowflake ID or channel objects from PyCord).

  • volume (Optional[int]) – The volume (0-100%) at which to play the audio. Defaults to 50%. This was added in v2.0.0

  • remove_after (Optional[Union[int, timedelta, datetime]]) –

    Deletes the message after:

    • int - provided amounts of successful sends to separate channels.

    • timedelta - the specified time difference

    • datetime - specific date & time

  • period (BaseMessagePeriod) – The sending period.

generate_log_context(file: FILE, succeeded_ch: List[VoiceChannel], failed_ch: List[Dict[str, Any]]) Dict[str, Any]#

Generates information about the message send attempt that is to be saved into a log.

Parameters:
  • audio (audio) – The audio that was streamed.

  • succeeded_ch (List[Union[discord.VoiceChannel]]) – List of the successfully streamed channels

  • failed_ch (List[Dict[discord.VoiceChannel, Exception]]) – List of dictionaries contained the failed channel and the Exception object

Returns:

  {
      sent_data:
      {
          streamed_audio: str - The filename that was streamed/youtube url
      },
      channels:
      {
          successful:
          {
              id: int - Snowflake id,
              name: str - Channel name
          },
          failed:
          {
              id: int - Snowflake id,
              name: str - Channel name,
              reason: str - Exception that caused the error
          }
      },
      type: str - The type of the message, this is always VoiceMESSAGE.
}

Return type:

Dict[str, Any]

property remove_after: int | datetime | None#

Returns the remaining send counts / date after which the message will be removed from the sending list. If the original type of the remove_after parameter to the message was of type int, this will return the maximum remaining amount of sends from all channels. If all the channels have been removed, this will return the original count remove_after parameter.

update(_init_options: dict | None = None, **kwargs: Any) Future#

New in version v2.0.

Changed in version v3.0: Turned into async api.

This is an asynchronous API operation. When returning from this function, the action is not immediately executed.

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.

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:
  • TypeError – Invalid keyword argument was passed

  • Other – Raised from .initialize() method.

async initialize(parent: Any, event_ctrl: EventController, channel_getter: Callable)#

This method initializes the implementation specific API objects and checks for the correct channel input context.

Parameters:

parent (daf.guild.GUILD) – The GUILD this message is in