Message data#

FILE#

class daf.messagedata.file.FILE(filename: str, data: bytes | str | None = None)#

FILE object used as a data parameter to the xMESSAGE objects. This is needed opposed to a normal file object because this way, you can edit the file after the framework has already been started.

Caution

This is used for sending an actual file and NOT it’s contents as text.

Parameters:
  • filename (str) – The filename of file you want to send.

  • data (Optional[Union[bytes, str]]) –

    Optional raw data or hex string represending raw data.

    If this parameter is not given (set as None), the data will be automatically obtained from filename file. Defaults to None.

    New in version 2.10.

Raises:
property stream: BytesIO#

Returns a stream to data provided at creation.

property filename: str#

The name of the file

property fullpath: str#

The full path to the file

property data: bytes#

Returns the raw binary data

property hex: str#

Returns HEX representation of the data.

to_dict()#

Returns dictionary representation of this data type.

New in version 2.10.

TextMessageData#

class daf.messagedata.TextMessageData(content: str | None = None, embed: ~_discord.embeds.Embed | None = None, files: ~typing.List[~daf.messagedata.file.FILE] = <factory>)#

Represents fixed text message data.

VoiceMessageData#

class daf.messagedata.VoiceMessageData(file: FILE)#

Represents fixed voice-like data.

DynamicMessageData#

class daf.messagedata.DynamicMessageData#

Represents dynamic message data. Can be both text or voice, but make sure text is only used on TextMESSAGE and voice on VoiceMESSAGE.

This needs to be inherited and the subclass needs to implement the get_data method, which accepts no parameters (pass those through the class).

Example

class MyCustomText(DynamicMessageData):
    def __init__(self, a: int):
        self.a = a

    def get_data(self):  # Can also be async
        return TextMessageData(f"Passed parameter was: {self.a}")

class MyCustomVoice(DynamicMessageData):
    def get_data(self):  # Can also be async
        return VoiceMessageData(FILE("./audio.mp3"))


TextMESSAGE(data=MyCustomText(152))
VoiceMESSAGE(data=MyCustomVoice())
abstract get_data() BaseMessageData#

The data getter method. Needs to be implemented in a subclass.

The method must return either a TextMessageData or a VoiceMessageData instance. It can also return None if no data is to be sent.