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:
- Raises:
FileNotFoundError – The
filename
does not exist.OSError – Could not read file
filename
.ValueError – The
data
parameter is of incorrect format.
- property stream: BytesIO¶
Returns a stream to data provided at creation.
- to_dict()¶
Returns dictionary representation of this data type.
Added 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¶
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 onVoiceMESSAGE
.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 aVoiceMessageData
instance. It can also returnNone
if no data is to be sent.