Messages#

TextMESSAGE#

class daf.message.TextMESSAGE(start_period: timedelta | int | None, end_period: int | timedelta, data: Iterable[str | Embed | FILE] | str | Embed | FILE | _FunctionBaseCLASS, channels: Iterable[int | TextChannel | Thread] | AutoCHANNEL, mode: Literal['send', 'edit', 'clear-send'] | None = 'send', start_in: timedelta | datetime | None = datetime.timedelta(0), remove_after: int | timedelta | datetime | None = None)#

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

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

Note

Slow mode period handling:

If the advertisement period is set less than the biggest slow-mode delay of the given channels, the period will be automatically set slightly above the slow-mode delay.

Parameters:
  • start_period (Union[int, timedelta, None]) –

    The value of this parameter can be:

    • None - Use this value for a fixed (not randomized) sending period

    • timedelta object - object describing time difference, if this is used, then the parameter represents the bottom limit of the randomized sending period.

  • end_period (Union[int, timedelta]) –

    If start_period is not None, then this represents the upper limit of randomized time period in which messages will be sent. If start_period is None, then this represents the actual time period between each message send.

    Caution

    When the period is lower than the remaining time, the framework will start incrementing the original period by original period until it is larger then the slow mode remaining time.

    Listing 16 Randomized sending period between 5 seconds and 10 seconds.#
    # Time between each send is somewhere between 5 seconds and 10 seconds.
    daf.TextMESSAGE(start_period=timedelta(seconds=5), end_period=timedelta(seconds=10), data="Second Message",
                    channels=[12345], mode="send", start_in=timedelta(seconds=0))
    
    Listing 17 Fixed sending period at 10 seconds#
    # Time between each send is exactly 10 seconds.
    daf.TextMESSAGE(start_period=None, end_period=timedelta(seconds=10), data="Second Message",
                    channels=[12345], mode="send", start_in=timedelta(seconds=0))
    

  • data (Union[str, discord.Embed, FILE, List[Union[str, discord.Embed, FILE]], _FunctionBaseCLASS]) –

    The data parameter is the actual data that will be sent using discord’s API. The data types of this parameter can be:

    • str (normal text),

    • discord.Embed,

    • FILE,

    • List/Tuple containing any of the above arguments (There can up to 1 string, up to 1 discord.Embed and up to 10 FILE objects.

    • Function that accepts any amount of parameters and returns any of the above types. To pass a function, YOU MUST USE THE data_function decorator on the function before passing the function to the daf.

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

    Changed in version v2.3: Can also be AutoCHANNEL

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

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

  • start_in (Optional[timedelta | datetime]) – When should the message be first sent. timedelta means the difference from current time, while datetime means actual first send time.

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

    Deletes the message after:

    • int - provided amounts of sends

    • timedelta - the specified time difference

    • datetime - specific date & time

generate_log_context(text: 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)#

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

Raises:
  • TypeError – Channel contains invalid channels

  • ValueError – Channel does not belong to the guild this message is in.

  • ValueError – No valid channels were passed to object”

async update(_init_options: dict | None = None, _init=True, **kwargs: Any)#

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.

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.

property created_at: datetime#

Returns the datetime of when the object was 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.

DirectMESSAGE#

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

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

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:
  • start_period (Union[int, timedelta, None]) –

    The value of this parameter can be:

    • None - Use this value for a fixed (not randomized) sending period

    • timedelta object - object describing time difference, if this is used, then the parameter represents the bottom limit of the randomized sending period.

  • end_period (Union[int, timedelta]) –

    If start_period is not None, then this represents the upper limit of randomized time period in which messages will be sent. If start_period is None, then this represents the actual time period between each message send.

    Listing 18 Randomized sending period between 5 seconds and 10 seconds.#
    # Time between each send is somewhere between 5 seconds and 10 seconds.
    daf.DirectMESSAGE(
        start_period=timedelta(seconds=5), end_period=timedelta(seconds=10), data="Second Message",
        mode="send", start_in=timedelta(seconds=0)
    )
    
    Listing 19 Fixed sending period at 10 seconds#
    # Time between each send is exactly 10 seconds.
    daf.DirectMESSAGE(
        start_period=None, end_period=timedelta(seconds=10), data="Second Message",
        mode="send", start_in=timedelta(seconds=0)
    )
    

  • data (Union[str, discord.Embed FILE, List[Union[str, discord.Embed, FILE]], _FunctionBaseCLASS]) –

    The data parameter is the actual data that will be sent using discord’s API. The data types of this parameter can be:

    • str (normal text),

    • discord.Embed,

    • FILE,

    • List/Tuple containing any of the above arguments (There can up to 1 string, up to 1 discord.Embed and up to 10 FILE objects.

    • Function that accepts any amount of parameters and returns any of the above types. To pass a function, YOU MUST USE THE data_function decorator on the function.

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

  • start_in (Optional[timedelta | datetime]) – When should the message be first sent. timedelta means the difference from current time, while datetime means actual first send time.

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

    Deletes the guild after:

    • int - provided amounts of sends

    • timedelta - the specified time difference

    • datetime - specific date & time

generate_log_context(success_context: Dict[str, bool | Exception | None], text: 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)#

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

Raises:

ValueError – Raised when the direct message channel could not be created

property created_at: datetime#

Returns the datetime of when the object was 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.

async update(_init_options: dict | None = 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.

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

VoiceMESSAGE#

class daf.message.VoiceMESSAGE(start_period: int | timedelta | None, end_period: int | timedelta, data: AUDIO | Iterable[AUDIO] | _FunctionBaseCLASS, channels: Iterable[int | VoiceChannel] | AutoCHANNEL, volume: int | None = 50, start_in: timedelta | datetime | None = datetime.timedelta(0), remove_after: int | timedelta | datetime | None = None)#

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

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:
  • start_period (Union[int, timedelta, None]) –

    The value of this parameter can be:

    • None - Use this value for a fixed (not randomized) sending period

    • timedelta object - object describing time difference, if this is used, then the parameter represents the bottom limit of the randomized sending period.

  • end_period (Union[int, timedelta]) –

    If start_period is not None, then this represents the upper limit of randomized time period in which messages will be sent. If start_period is None, then this represents the actual time period between each message send.

    Listing 20 Randomized sending period between 5 seconds and 10 seconds.#
    # Time between each send is somewhere between 5 seconds and 10 seconds.
    daf.VoiceMESSAGE(
        start_period=timedelta(seconds=5), end_period=timedelta(seconds=10), data=daf.AUDIO("msg.mp3"),
        channels=[12345], start_in=timedelta(seconds=0), volume=50
    )
    
    Listing 21 Fixed sending period at 10 seconds#
    # Time between each send is exactly 10 seconds.
    daf.VoiceMESSAGE(
        start_period=None, end_period=timedelta(seconds=10), data=daf.AUDIO("msg.mp3"),
        channels=[12345], start_in=timedelta(seconds=0), volume=50
    )
    

  • data (AUDIO) –

    The data parameter is the actual data that will be sent using discord’s API. The data types of this parameter can be:

    • AUDIO object.

    • Function that accepts any amount of parameters and returns an AUDIO object. To pass a function, YOU MUST USE THE data_function decorator on the function.

  • channels (Union[Iterable[Union[int, discord.VoiceChannel]], daf.message.AutoCHANNEL]) –

    Changed in version v2.3: Can also be 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

  • start_in (Optional[timedelta | datetime]) – When should the message be first sent. timedelta means the difference from current time, while datetime means actual first send time.

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

    Deletes the message after:

    • int - provided amounts of sends

    • timedelta - the specified time difference

    • datetime - specific date & time

generate_log_context(audio: AUDIO, 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]

async initialize(parent: Any)#

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

Raises:
  • TypeError – Channel contains invalid channels

  • ValueError – Channel does not belong to the guild this message is in.

  • ValueError – No valid channels were passed to object”

property created_at: datetime#

Returns the datetime of when the object was 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.

async update(_init_options: dict | None = 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.

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