Message
Represents a message from Discord.
Attributes
None
, MessageActivity
Sent with rich presence related embeds. Defaults to None
.
None
, MessageApplication
Sent with rich presence related embeds. Defaults to None
.
int
The application's identifier who sent the message. Defaults to 0
.
Attachments sent with the message. Defaults to None
.
The author of the message. Can be any user type and if not found, then set as ZEROUSER
.
None
, MessageCall
Call information of the message. Applicable if the message's type is .call
. Defaults to None
.
int
The channel's identifier where the message is sent. Defaults to 0
Components attached to the message. Defaults to None
.
None
, str
The message's content. Defaults to None
.
None
, datetime
The time when the message was edited, or None
if it was not.
Pinning or (un)suppressing a message will not change it's edited value.
Defaults to None
.
Embeds included with the message.
If a message contains links then those links' embeds might not be included with the initial payload, but only with a followup one.
Defaults to None
.
The message's flags. Defaults to MessageFlag(0)
.
int
The channel's guild's identifier. Defaults to 0Ë™.
int
The unique identifier number of the message. Defaults to 0
.
None
, MessageInteraction
Present if the message is a response to an InteractionEvent
. Defaults to None
.
Cross guild channel mentions of a crosspost message if applicable. Defaults to None
.
bool
Whether the message contains @everyone
, @here
. Defaults to False
.
None
, tuple
of int
The mentioned roles' identifiers. Defaults to None
.
The mentioned users by the message. Defaults to None
.
None
, str
A nonce that is used for optimistic message sending. If a message is created with a nonce, then it should be shown up at the message's received payload as well. Defaults to None
.
bool
Whether the message is pinned. Defaults to False
.
None
, ReactionMapping
A dictionary like object that contains the reactions on the message. Defaults to None
.
If all reactions are removed from a message,
.reactions
will not default back toNone
.
None
, Message
The referenced message. The message can be partial.
Set when the message is a reply, a crosspost or when is a pin message.
Defaults to None
.
None
, Resolved
Resolved entities of selected options.
Defaults to None
.
None
, MessageRoleSubscription
Additional role subscription information attached to the message. Defaults to None
.
The stickers sent with the message. Defaults to None
.
None
, Channel
The thread that was started from this message. Defaults to None
.
bool
Whether the message is "text to speech". Defaults to False
.
The type of the message. Defaults to MessageType.default
.
Mentioned channels by the message. Parsed from .content
. Defaults to None
.
Cache field used by .mentioned_channels
.
int
Bitwise mask used to track the message's state.
Notes
Message instances are weakreferable.
The content
, embeds
, attachments
and the components
fields are restricted for the message content intent.
Properties
attachment
channel
channel_mentions
Deprecated and will be removed in 2023 November.
clean_content
Returns the message's clean content, what actually depends on the message's type. By default it is the message's content with transformed mentions, but for different message types it means different things.
Returns
clean_content : None
, str
Notes
The converting can not display join messages, call messages and private channel names correctly.
clean_embeds
Returns the message's not link typed embeds with converted content without mentions.
Returns
clean_embeds : list
of Embed
Notes
Not changes the original embeds of the message.
contents
A list of all of the contents sent in the message. It means the message's content if it has and the content of the message's embeds.
Returns
contents : list
of str
created_at
When the entity was created.
Returns
created_at : datetime
cross_mentions
Deprecated and will be removed in 2023 November.
deleted
Returns whether the message is deleted.
Defaults to False
.
Returns
deleted : bool
embed
everyone_mention
Deprecated and will be removed in 2023 November.
guild
mentioned_channels
The mentioned channels by the message. If there is non returns None
.
Returns
mentioned_channels : None
, tuple
of Channel
mentioned_roles
The mentioned roles by the message. If there is non, returns None
.
Returns
role_mentions : None
, tuple
of Role
mentions
Returns a list of all the mentions sent at the message.
Returns
mentions : list
of (str
('everyone'
), ClientUserBase
, Role
, Channel
)
partial
Returns whether the message is partial.
Returns
partial : bool
role_mention_ids
Deprecated and will be removed in 2023 November.
role_mentions
Deprecated and will be removed in 2023 November.
sticker
url
Returns a jump url to the message. If the message's channel is a partial guild channel, returns None
.
This function is a shared property of Message
-s.
Returns
url : str
user_mentions
Returns whether the message has .user_mentions
set as its non-default value.
Defaults to None
.
Returns
user_mentions : None
, tuple
of UserBase
Methods
(...)
__new__Creates a new partial message with the given fields.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
activity |
| Message's activity information, sent with rich presence related embeds. | ||
application |
| Message's application information, sent with rich presence related embeds. | ||
application_id |
| The application or its identifier who sent the message. | ||
attachments |
| Attachments sent with the message. | ||
author | The author of the message. | |||
call |
| Call information of the message. | ||
components |
| Components attached to the message. | ||
content |
| The message's content. | ||
edited_at |
| The time when the message was edited. | ||
embeds |
| Embeds included with the message. | ||
flags |
| The message's flags. | ||
interaction |
| Present if the message is a response to an | ||
mentioned_channels_cross_guild |
| Cross guild channel mentions of a crosspost message if applicable. | ||
mentioned_everyone |
| Whether the message contains | ||
mentioned_role_ids |
| The mentioned roles' identifiers. | ||
mentioned_users |
| The mentioned users by the message. | ||
message_type |
| The type of the message. | ||
nonce |
| A nonce that is used for optimistic message sending. If a message is created with a nonce, then it should be shown up at the message's received payload as well. | ||
reactions |
| A dictionary like object that contains the reactions on the message | ||
referenced_message |
| The referenced message. | ||
resolved |
| Resolved entities of selected options. | ||
role_subscription |
| Additional role subscription information attached to the message. | ||
pinned |
| Whether the message is pinned. | ||
stickers |
| The stickers sent with the message. | ||
thread |
| The thread that was started from this message. | ||
tts |
| Whether the message is "text to speech". |
Raises
TypeError
- If a parameter's type is incorrect.
ValueError
- If a parameter's value is incorrect.
()
copyCopies the message returning a new partial one.
Returns
new : instance<type<self>>
(...)
copy_withCopies the message with the given fields.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
activity |
| Message's activity information, sent with rich presence related embeds. | ||
application |
| Message's application information, sent with rich presence related embeds. | ||
application_id |
| The application or its identifier who sent the message. | ||
attachments |
| Attachments sent with the message. | ||
author | The author of the message. | |||
call |
| Call information of the message. | ||
components |
| Components attached to the message. | ||
content |
| The message's content. | ||
edited_at |
| The time when the message was edited. | ||
embeds |
| Embeds included with the message. | ||
flags |
| The message's flags. | ||
interaction |
| Present if the message is a response to an | ||
mentioned_channels_cross_guild |
| Cross guild channel mentions of a crosspost message if applicable. | ||
mentioned_everyone |
| Whether the message contains | ||
mentioned_role_ids |
| The mentioned roles' identifiers. | ||
mentioned_users |
| The mentioned users by the message. | ||
message_type |
| The type of the message. | ||
nonce |
| A nonce that is used for optimistic message sending. If a message is created with a nonce, then it should be shown up at the message's received payload as well. | ||
reactions |
| A dictionary like object that contains the reactions on the message | ||
referenced_message |
| The referenced message. | ||
resolved |
| Resolved entities of selected options. | ||
role_subscription |
| Additional role subscription information attached to the message. | ||
pinned |
| Whether the message is pinned. | ||
stickers |
| The stickers sent with the message. | ||
thread |
| The thread that was started from this message. | ||
tts |
| Whether the message is "text to speech". |
Returns
new : instance<type<self>>
Raises
TypeError
- If a parameter's type is incorrect.
ValueError
- If a parameter's value is incorrect.
()
customDeprecated and will be removed in 2024 April.
(reaction, user)
did_reactReturns whether the given user reacted with the given emoji on the message.
Parameter | Type | Description |
---|---|---|
reaction | The reaction. | |
user | The reactor. |
Returns
did_react : bool
(data)
from_dataCreates a new message object form the given message payload. If the message already exists, picks it up.
Parameter | Type | Description |
---|---|---|
data |
| Message data. |
Returns
self : instance<cls>
()
has_activity()
has_any_content_fieldReturns whether the message has any content field. Can be used to check whether the bot receiving / requesting the message has the message content intent.
Returns
has_any_content_field : bool
()
has_applicationReturns whether the message has .application
set as its non-default value.
Returns
has_application : bool
()
has_application_idReturns whether the message has .application_id
set as its non-default value.
Returns
has_application_id : bool
()
has_attachmentsReturns whether the message has .attachments
set as its non-default value.
Returns
has_attachments : bool
()
has_channel_mentionsDeprecated and will be removed in 2023 November.
()
has_componentsReturns whether the message has .components
set as its non-default value.
Returns
has_components : bool
()
has_content()
has_cross_mentionsDeprecated and will be removed in 2023 November.
()
has_deletedDeprecated and will be removed in 2023 November.
()
has_edited_atReturns whether the message has .edited_at
set as its non-default value.
Returns
has_edited_at : bool
()
has_embeds()
has_everyone_mentionDeprecated and will be removed in 2023 November.
()
has_flags()
has_interaction()
has_mentioned_channelsReturns whether the message has .mentioned_channels
set as its non-default value.
Returns
has_channel_mentions : bool
()
has_mentioned_channels_cross_guildReturns whether the message has .mentioned_channels_cross_guild
set as its non-default value.
Returns
has_mentioned_channels_cross_guild : bool
()
has_mentioned_everyoneReturns whether the message has .mentioned_everyone
set as its non-default value.
Returns
has_mentioned_everyone : bool
()
has_mentioned_role_idsReturns whether the message has .mentioned_role_ids
set as its non-default value.
Returns
has_role_mention_ids : bool
()
has_mentioned_rolesReturns whether the message has .has_mentioned_roles
set as its non-default value.
Returns
has_mentioned_roles : bool
()
has_mentioned_users()
has_nonce()
has_partialDeprecated and will be removed in 2023 November.
()
has_pinned()
has_reactionsReturns whether the message has any reactions.
A message can have no reactions even if its
.reactions
is not set as its default value. This can happen if reactions were removed from the message.
Returns
has_reactions : bool
()
has_referenced_messageReturns whether the message has .referenced_message
set as its non-default value.
Returns
has_referenced_message : bool
()
has_role_mention_idsDeprecated and will be removed in 2023 November.
()
has_role_mentionsDeprecated and will be removed in 2023 November.
()
has_role_subscriptionReturns whether the message has .role_subscription
set as its non-default value.
Returns
has_role_subscription : bool
()
has_stickers()
has_thread()
has_tts()
has_type()
has_user_mentionsDeprecated and will be removed in 2023 November.
()
hash_resolved()
is_deletableReturns whether the message can be deleted.
Returns
is_deletable : bool
()
iter_attachmentsIterates over the attachments of the message.
This method is an iterable generator.
Yields
attachment : Attachment
()
iter_componentsIterates over the components of the message.
This method is an iterable generator.
Yields
component : Component
()
iter_contentsIterates over the contents of the message.
This method is an iterable generator.
Yields
content : str
()
iter_embeds()
iter_mentioned_channelsIterates over the mentioned channels in the message.
This method is an iterable generator.
Yields
mentioned_channel : Channel
()
iter_mentioned_channels_cross_guildIterates over the mentioned channels from an other guild.
This method is an iterable generator.
Yields
mentioned_channel : Channel
()
iter_mentioned_role_idsIterates over the mentioned roles' identifiers in the message.
This method is an iterable generator.
Yields
mentioned_role_id : int
()
iter_mentioned_rolesIterates over the mentioned roles in the message.
This method is an iterable generator.
Yields
mentioned_role : Role
()
iter_mentioned_usersIterates over the mentioned users in the message.
This method is an iterable generator.
Yields
mentioned_user : ClientUserBase
()
iter_stickersIterates over the stickers of the message.
This method is an iterable generator.
Yields
sticker : Sticker
(message_id, ...)
precreatePrecreates the message with the given parameters. Precreated messages are picked up when the message's data is received with the same id.
First tries to find whether a message exists with the given id. If it does and it is partial, updates it with the given parameters, else it creates a new one.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
message_id |
| The message's id. | ||
**keyword_parameters | keyword parameters | Additional predefined attributes for the message. | ||
activity |
| Message's activity information, sent with rich presence related embeds. | ||
application |
| Message's application information, sent with rich presence related embeds. | ||
application_id |
| The application or its identifier who sent the message. | ||
attachments |
| Attachments sent with the message. | ||
author | The author of the message. | |||
call |
| Call information of the message. | ||
channel |
| Alternative for | ||
channel_id |
| The channel's identifier where the message was created at. | ||
components |
| Components attached to the message. | ||
content |
| The message's content. | ||
edited_at |
| The time when the message was edited. | ||
embeds |
| Embeds included with the message. | ||
flags |
| The message's flags. | ||
guild |
| Alternative for | ||
guild_id |
| The guild's identifier where the message was created at. | ||
interaction |
| Present if the message is a response to an | ||
mentioned_channels_cross_guild |
| Cross guild channel mentions of a crosspost message if applicable. | ||
mentioned_everyone |
| Whether the message contains | ||
mentioned_role_ids |
| The mentioned roles' identifiers. | ||
mentioned_roles |
| Alternative for | ||
mentioned_users |
| The mentioned users by the message. | ||
message_type |
| The type of the message. | ||
nonce |
| A nonce that is used for optimistic message sending. If a message is created with a nonce, then it should be shown up at the message's received payload as well. | ||
reactions |
| A dictionary like object that contains the reactions on the message | ||
referenced_message |
| The referenced message. | ||
resolved |
| Resolved entities of selected options. | ||
role_subscription |
| Additional role subscription information attached to the message. | ||
pinned |
| Whether the message is pinned. | ||
stickers |
| The stickers sent with the message. | ||
thread |
| The thread that was started from this message. | ||
tts |
| Whether the message is "text to speech". |
Returns
self : instance<cls>
Raises
TypeError
If a parameter's type is invalid.
ValueError
If a parameter's value is invalid.
(...)
to_dataTries to convert the message back to json serializable dictionary.
Parameter | Type | Optional | Keyword only | Default | Description |
---|---|---|---|---|---|
defaults |
|
| Whether fields with their default value should be included as well. | ||
include_internals |
|
| Whether internal fields should be included as well. | ||
recursive |
|
| Whether the referenced message's data should be included as well. |
Returns
data : dict
of (str
, object
) items
()
to_message_reference_dataTries to convert the message to json serializable dictionary representing a message reference.
Returns
data : dict
of (str
, object
)
(reaction, user)
_add_reactionAdds a reaction to the message.
Parameter | Type | Description |
---|---|---|
reaction | The reaction. | |
user | The reactor user. |
()
_clear_cacheClears the message's cache fields.
(message_id, ...)
_create_emptyCreates a message with default parameters set.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
message_id |
| The message's identifier. | ||
channel_id |
|
| The channel's identifier where the message was created at. | |
guild_id |
|
| The guild's identifier where the message was created at. |
Returns
self : Message
(data)
_create_from_partial_dataCreates a message from message reference data.
If the message is loaded already, returns that instead.
Parameter | Type | Description |
---|---|---|
data |
| Message reference data. |
Returns
self : instance<cls>
(message_id, channel_id, guild_id)
_create_from_partial_fieldsCreates a new message from the given fields describing it.
Parameter | Type | Description |
---|---|---|
message_id |
| The unique identifier number of the represented message. |
channel_id |
| The respective message's channel's identifier. |
guild_id |
| The respective message's guild's identifier. |
Returns
self : instance<cls>
(data)
_create_message_was_up_to_dateCreates a new message object form the given message payload. If the message already exists, picks it up.
Parameter | Type | Description |
---|---|---|
data |
| Message data. |
Returns
self : instance<cls>
The created or found message instance.
was_up_to_date : bool
Whether the message was found in the cache.
(data)
_difference_update_attributesUpdates the message and returns it's overwritten attributes as a dict
with a attribute-name
- old-value
relation.
A special case is if a message is (un)pinned or (un)suppressed , because then the returned dict is not going to contain 'edited_at'
, only 'pinned'
, 'flags'
. If the embeds are (un)suppressed of the message, then the returned dict might contain also an 'embeds'
key.
Parameter | Type | Description |
---|---|---|
data |
| Message data received from Discord. |
Returns
old_attributes : dict
of (str
, object
) items
All item in the returned dict is optional.
Returned Data Structure
Keys | Values |
---|---|
attachments | None , tuple of Attachment |
call | None , MessageCall |
components | None , tuple of Component |
content | None , str |
edited_at | None , datetime |
embeds | None , tuple of Embed |
flags | MessageFlag |
mentioned_channels_cross_guild | None , tuple of Channel |
mentioned_everyone | bool |
mentioned_role_ids | None , tuple of int |
mentioned_users | None , tuple of ClientUserBase |
pinned | bool |
resolved | None , Resolved |
()
_get_hash_partialReturns a partial message's hash value.
Returns
hash_value : int
()
_get_mentioned_channelsLooks up the .contents
of the message and searches channel mentions in them.
Invalid channel mentions are ignored.
Returns
channel_mentions : None
, tuple
of Channel
The parsed channel mentions.
(other)
_is_equal_same_typeReturns whether self is equal to other. Other must be same type as self.
Parameter | Type | Description |
---|---|---|
other |
| The other instance. |
Returns
is_equal : bool
(data)
_late_initSome message fields might be missing after receiving a payload. This method is called to check and set those if multiple payload is received.
The fields are:
content
components
embeds
interaction
Since we update the content fields anyways, in this method we only update the interaction
field.
Parameter | Type | Description |
---|---|---|
data |
| Message data. |
(reaction, user)
_remove_reactionRemoves a reaction to the message.
Parameter | Type | Description |
---|---|---|
reaction | The reaction. | |
user | The user who removed their reaction. |
(emoji)
_remove_reaction_emojiRemoves all reactions of an emoji from the message.
Parameter | Type | Description |
---|---|---|
emoji | The emoji to remove it's reactions. |
Returns
removed_reactions : None
, dict
of (Reaction
, ReactionMappingLine
) items
(data, ...)
_set_attributesFinishes the message's initialization process by setting it's attributes.
This method required
.id
and.reactions
to be set already.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
data |
| Message data. | ||
creation |
|
| Whether the entity was just created. |
(data)
_update_attributesUpdates the message with the given data by overwriting it's old attributes.
Parameter | Type | Description |
---|---|---|
data |
| Message data received from Discord. |
(data)
_update_content_fieldsUpdates the message's content attributes with the given data by overwriting it's old attributes.
Parameter | Type | Description |
---|---|---|
data |
| Message data received from Discord. |
(data)
_update_embedAfter getting a message, it's embeds might be updated from links, or with image, video sizes. If it happens this method is called.
Parameter | Type | Description |
---|---|---|
data |
| Message data received from Discord. |
Returns
change_state: int
Possible values:
Respective name | Value |
---|---|
EMBED_UPDATE_NONE | 0 |
EMBED_UPDATE_SIZE_UPDATE | 1 |
EMBED_UPDATE_EMBED_ADD | 2 |
EMBED_UPDATE_EMBED_REMOVE | 3 |
(data)
_update_embed_no_returnUpdates the message's embeds.
Parameter | Type | Description |
---|---|---|
data |
| Message data received from Discord. |
()
__eq__Returns whether the two messages are equal.
(code)
__format__Formats the message in a format string.
Parameter | Type | Description |
---|---|---|
code |
| The option on based the result will be formatted. |
Returns
message : str
Raises
ValueError
Unknown format code.
Examples
>>>> from hata import Message
>>>> message = Message.precreate(103589856105356645, content = 'Fluffy nekos')
>>>> message
<Message id = 103589856105356645, length = 12, author = <User name = '#0000'>>
>>>> # No code stands for str(message), what is same as repr(message) for the time being.
>>>> f'{message}'
'<Message id = 103589856105356645, length = 12, author = <User name = '#0000'>>'
>>>> # 'c' stands for created at.
>>>> f'{message:c}'
'2015-10-13 20:29:06'
>>>> # 'e' stands for edited.
>>>> f'{message:e}'
'never'
>>>> from datetime import datetime
>>>> message = Message(edited_at = datetime.utcnow())
>>>> message
<Message id = 0, length = 0, <User name = '#0000'>>
>>>> f'{message:e}'
'2015-10-13 20:29:06'
()
__ge__Whether this entity's id is greater or equal than the other's.
()
__getattr__Drops a rich attribute error.
()
__gt__Whether this entity's id is greater than the other's.
()
__hash__Returns the message's hash.
()
__le__Whether this entity's id is less or equal than the other's.
()
__len__Returns the message's total length.
()
__lt__Whether this entity's id is less than the other's.
()
__ne__Returns whether the two messages are not equal.
()
__repr__Returns the representation of the message.