Message
Message (BaseDiscordObject, ComponentAdder, EmbedAdder)
Message containing infomation about it's content, origin, authors, etc.
Attributes:
Name | Type | Description |
---|---|---|
id |
Snowflake |
Unique ID of the message. |
channel_id |
Snowflake |
Unique ID of the channel the message came from. |
guild_id |
Snowflake|None |
Unique ID of the channel the message came from. Defaults to None. |
guild |
Guild|None |
Actual guild object item is from. This will autopopulate from the API if it is not present. |
author |
User |
The author of the message. |
member |
Member |
If the message was in a guild, this will be the Member object of the author. |
content |
str |
The actual content of the message. |
timestamp |
datetime |
Date and time the message was posted. |
edited_timestamp |
datetime|None |
If the message has been edited, this is the date and time it was. |
tts |
bool |
Text to speech flag. |
mention_everyone |
bool |
Message had an @everyone in it. |
mentions |
[User] |
List of mentioned User. |
mention_roles |
[Role] |
List of mentioned Role. |
mention_channels |
[Channel] |
List of mentioned Channel. Note that each channel will be the correct type. |
embeds |
[Embed] |
List of rich Embed objects. |
nonce |
str|None |
Nonce used to send the message. |
pinned |
bool |
True if message is pinned in the channel. |
webhook_id |
Snowflake|None |
ID of the webhook used to send this message. |
type |
MESSAGE_TYPE |
Enumeration of the type of message. |
application_id |
Snowflake|None |
ID of the application that send the message. |
message_reference |
MessageReference|None |
data showing the source of a crosspost, channel follow add, pin, or reply message |
flags |
int |
Bitfield of message flags. |
referenced_message |
Message|None |
Message object refereed to in message_reference. |
thread |
Channel |
Thread the message is a part of. |
components |
[Component] |
List of components in the message if it is an interaction. |
channel
property
readonly
Attempt to grab channel from the API.
guild
property
readonly
Attempt to grab guild from the API.
MESSAGE_TYPE (IntEnum)
Types of messages.
formatter
Helper formatting functions.
These mostly implement the functions found in the Discord API docs.
Examples:
When generating a string for a message, the formatter class provides a quick shortcut to get and use the various formatters.
message = Message()
f'The time is {message.formatter.timestamp()}!'
TIMESTAMP_FLAGS (Enum)
Types of timestamp displays.
Attributes:
Name | Type | Description |
---|---|---|
SHORT_TIME |
enum |
16:20 |
LONG_TIME |
enum |
16:20:30 |
SHORT_DATE |
enum |
20/04/2021 |
SHORT_DATE_TIME |
enum |
20 April 2021 16:20 |
LONG_DATE |
enum |
20 April 2021 |
LONG_DATE_TIME |
enum |
Tuesday, 20 April 2021 16:20 |
RELATIVE_TIME |
enum |
2 months ago |
DEFAULT |
enum |
20 April 2021 16:20 |
timestamp(timestamp=None, flag=<TIMESTAMP_FLAGS.SHORT_DATE_TIME: 'f'>)
classmethod
Return valid timestamp string. Discord will display this in a useful way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamp |
datetime |
The timestamp to parse, can be omitted to use |
None |
flag |
TIMESTAMP_FLAGS|str |
Flag to use when parsing the timestamp on the client. |
<TIMESTAMP_FLAGS.SHORT_DATE_TIME: 'f'> |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference to a point in time. |
user(user)
classmethod
Return valid mention string for the user's name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
Snowflake|User|Member |
User or User's ID to mention. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a User by name. |
user_nickname(user)
classmethod
Return valid mention string for the user's nickname.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
Snowflake|User|Member |
User or User's ID to mention. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a User by nickname. |
channel(channel)
classmethod
Return valid mention string for the channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel |
Snowflake|Channel |
Channel or channel ID to mention. Any subclass of Channel is accepted. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a Channel. |
role(role)
classmethod
Return valid mention string for the role.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role |
Snowflake|Role |
Role or role's ID to mention. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a Role. |
add_components(self)
inherited
Start adding components by starting an ACTION_ROW.
to_dict(self)
inherited
Convert object to dictionary suitable for API or other generic useage.
__init__(self, content=None)
special
Init.
from_dict(self, data)
Parse a Message from an API compliant dict.
to_sendable_dict(self)
Sending a message only allows a subset of attributes. Ignore anything else about this message when producing that dict.
validate(self)
Validate object is prepared for dispatch to discord.
add_embeds(self)
inherited
Add embeds to the object.
MessageReference (BaseDiscordObject)
Slim data holding class.
Attributes:
Name | Type | Description |
---|---|---|
message_id |
Snowflake|None |
ID of the originating message. |
channel_id |
Optional[dyscord.objects.snowflake.Snowflake] |
(Snowflake|None): ID of the originating message's channel. |
guild_id |
Optional[dyscord.objects.snowflake.Snowflake] |
(Snowflake|None): ID of the originating message's guild. |
fail_if_not_exists |
bool|None |
When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true |
to_dict(self)
inherited
Convert object to dictionary suitable for API or other generic useage.
validate(self)
inherited
Check for valid object type.
Exceptions:
Type | Description |
---|---|
NotImplementedError |
Always. |
from_dict(self, data)
Parse a MessageReference from an API compliant dict.
MessageUpdate (Message)
Duplicate of the Message class, but most fields are now annotated as optional.
channel
inherited
property
readonly
Attempt to grab channel from the API.
guild
inherited
property
readonly
Attempt to grab guild from the API.
MESSAGE_TYPE (IntEnum)
inherited
Types of messages.
formatter
inherited
Helper formatting functions.
These mostly implement the functions found in the Discord API docs.
Examples:
When generating a string for a message, the formatter class provides a quick shortcut to get and use the various formatters.
message = Message()
f'The time is {message.formatter.timestamp()}!'
TIMESTAMP_FLAGS (Enum)
Types of timestamp displays.
Attributes:
Name | Type | Description |
---|---|---|
SHORT_TIME |
enum |
16:20 |
LONG_TIME |
enum |
16:20:30 |
SHORT_DATE |
enum |
20/04/2021 |
SHORT_DATE_TIME |
enum |
20 April 2021 16:20 |
LONG_DATE |
enum |
20 April 2021 |
LONG_DATE_TIME |
enum |
Tuesday, 20 April 2021 16:20 |
RELATIVE_TIME |
enum |
2 months ago |
DEFAULT |
enum |
20 April 2021 16:20 |
timestamp(timestamp=None, flag=<TIMESTAMP_FLAGS.SHORT_DATE_TIME: 'f'>)
classmethod
Return valid timestamp string. Discord will display this in a useful way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamp |
datetime |
The timestamp to parse, can be omitted to use |
None |
flag |
TIMESTAMP_FLAGS|str |
Flag to use when parsing the timestamp on the client. |
<TIMESTAMP_FLAGS.SHORT_DATE_TIME: 'f'> |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference to a point in time. |
user(user)
classmethod
Return valid mention string for the user's name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
Snowflake|User|Member |
User or User's ID to mention. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a User by name. |
user_nickname(user)
classmethod
Return valid mention string for the user's nickname.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
Snowflake|User|Member |
User or User's ID to mention. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a User by nickname. |
channel(channel)
classmethod
Return valid mention string for the channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel |
Snowflake|Channel |
Channel or channel ID to mention. Any subclass of Channel is accepted. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a Channel. |
role(role)
classmethod
Return valid mention string for the role.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role |
Snowflake|Role |
Role or role's ID to mention. |
required |
Returns:
Type | Description |
---|---|
str |
Valid string to use as part of a discord message to reference a Role. |
add_components(self)
inherited
Start adding components by starting an ACTION_ROW.
to_dict(self)
inherited
Convert object to dictionary suitable for API or other generic useage.
from_dict(self, data)
inherited
Parse a Message from an API compliant dict.
to_sendable_dict(self)
inherited
Sending a message only allows a subset of attributes. Ignore anything else about this message when producing that dict.
validate(self)
inherited
Validate object is prepared for dispatch to discord.
add_embeds(self)
inherited
Add embeds to the object.