Message¶
discord_http.message module¶
- class discord_http.message.Attachment(*, state, data)¶
Bases:
objectRepresents an attachment in a message.
- Parameters:
state (DiscordAPI)
data (dict)
- application: Application | None¶
The application that created the clip, if applicable.
- property flags: AttachmentFlags¶
The flags of the attachment.
- async fetch(*, use_cached=False) bytes¶
Fetches the file from the attachment URL and returns it as bytes.
- Parameters:
use_cached (
bool) – Whether to use the cached URL or not, defaults to False- Return type:
- Returns:
The attachment as bytes
- Raises:
HTTPException – If the request returned anything other than 2XX
- async save(path, *, use_cached=False) int¶
Fetches the file from the attachment URL and saves it locally to the path.
- class discord_http.message.JumpURL(*, state, url=None, guild_id=None, channel_id=None, message_id=None)¶
Bases:
objectRepresents a jump URL to a message.
- Parameters:
state (DiscordAPI)
url (str | None)
guild_id (int | None)
channel_id (int | None)
message_id (int | None)
- property guild: Guild | PartialGuild | None¶
The guild the message was sent in.
- property channel: BaseChannel | PartialChannel | None¶
The channel the message was sent in.
If guild and channel cache is enabled, it can also return full channel object.
- async fetch_channel() BaseChannel¶
Returns the channel the message was sent in.
- Return type:
- property message: PartialMessage | None¶
The message if a message_id is available.
- class discord_http.message.Message(*, state, data, guild=None)¶
Bases:
PartialMessageRepresents a message object.
- Parameters:
state (DiscordAPI)
data (dict)
guild (PartialGuild | None)
- property channel: BaseChannel | PartialChannel¶
The channel the message was sent in.
- async create_public_thread(name, *, auto_archive_duration=60, rate_limit_per_user=None, reason=None) PublicThread¶
Create a public thread from the message.
- Parameters:
- Return type:
- Returns:
The created thread
- Raises:
If auto_archive_duration is not 60, 1440, 4320 or 10080 - If rate_limit_per_user is not between 0 and 21600 seconds
- async edit(*, content=<MISSING>, embed=<MISSING>, embeds=<MISSING>, view=<MISSING>, attachment=<MISSING>, attachments=<MISSING>, allowed_mentions=<MISSING>, flags=<MISSING>) Message¶
Edit the message.
- Parameters:
attachments (
list[File] |None) – New attachments of the messageallowed_mentions (
AllowedMentions|None) – Allowed mentions of the messageflags (
MessageFlags|None) – Flags of the message
- Return type:
- Returns:
The edited message
- async expire_poll() Message¶
Immediately end the poll, then returns new Message object.
This can only be done if you created it
- Return type:
- async fetch_poll_voters(answer, after=None, limit=100) AsyncIterator[User]¶
Fetch the users who voted for this answer.
- Parameters:
- Yields:
User object of people who voted
- Return type:
- async forward(*, channel_id) Message¶
Forwards the message to another channel.
This does not accept any normal message parameters, only channel ID.
- property guild: Guild | PartialGuild | None¶
The guild the message was sent in.
- async reply(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, view=<MISSING>, tts=False, flags=<MISSING>, allowed_mentions=<MISSING>, stickers=<MISSING>, nonce=<MISSING>, enforce_nonce=False, shared_client_theme=<MISSING>, delete_after=None) Message¶
Sends a reply to a message in a channel.
- Parameters:
tts (
bool|None) – If the message should be sent as a TTS messagetype – The type of response to the message
allowed_mentions (
AllowedMentions|None) – The allowed mentions for the messagestickers (
list[PartialSticker|Snowflake|int] |None) – Stickers from the guild to send with the message, max 3nonce (
int|str|None) – Nonce to verify the message was sent, max 25 charactersenforce_nonce (
bool) – Whether the nonce should be enforced, returning the existing message if it was already sentshared_client_theme (
SharedClientTheme|None) – Client theme to share with the messagedelete_after (
float|None) – If provided, the message will be deleted after the given number of secondsflags (
MessageFlags|None) – Message flags to send with the message
- Return type:
- Returns:
The message object
- type: MessageType¶
The type of the message.
- application_id: int | None¶
The ID of the application, if the message is an interaction or sent by an application-owned webhook.
- attachments: list[Attachment]¶
The attachments of the message.
- stickers: list[PartialSticker]¶
The stickers of the message.
- reactions: list[MessageReaction]¶
The reactions to the message.
- reference: MessageReference | None¶
The reference to another message, if any.
- resolved_forward: list[MessageSnapshot]¶
The resolved forward messages, if any.
- interaction: MessageInteraction | None¶
The interaction associated with the message, if any.
- role_subscription_data: RoleSubscriptionData | None¶
The role subscription data of the message, if any.
- call: MessageCall | None¶
The call associated with the message, if any.
- property pretty_content: str¶
Same as content, but mentions are parsed if possible.
User, role and channel mentions are replaced with their names, slash command mentions with /command, mentions that can not be resolved are left as-is.
- property escaped_content: str¶
Same as content, but with markdown characters escaped, showing the message as it was written.
- property flags: MessageFlags¶
The flags of the message.
- property activity: MessageActivity | None¶
The Rich Presence activity of the message, if any.
- property application: Application | None¶
The Rich Presence application of the message, if any.
The client theme shared via the message, if any.
- property emojis: list[EmojiParser]¶
The emojis in the message.
- property role_mentions: list[Role | PartialRole]¶
The role mentions in the message.
Can return full role object if guild and role cache is enabled
- property channel_mentions: list[BaseChannel | PartialChannel]¶
The channel mentions in the message.
Can return full channel object if guild and channel cache is enabled
- class discord_http.message.MessageActivity(type, party_id)¶
Bases:
NamedTupleRepresents the Rich Presence activity of a message.
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- class discord_http.message.MessageCall(participants, ended_timestamp)¶
Bases:
NamedTupleRepresents the call data of a message.
- Parameters:
participants (list[PartialUser])
ended_timestamp (datetime | None)
- participants: list[PartialUser]¶
Alias for field number 0
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- class discord_http.message.MessageInteraction(*, state, data)¶
Bases:
PartialBaseRepresents a message interaction.
- Parameters:
state (DiscordAPI)
data (dict)
- original_response_message_id: int | None¶
The ID of the original response message, only present on follow-up messages.
- target_message_id: int | None¶
The ID of the message the command was run on, only present on message commands.
- interacted_message_id: int | None¶
The ID of the message that contained the component, only present on component interactions.
- triggering_interaction_metadata: MessageInteraction | None¶
The interaction that opened the modal, only present on modal submit interactions.
- property type: InteractionType¶
The type of the interaction.
- property authorizing_integration_owners: dict[IntegrationType, int]¶
The installation contexts that authorized the interaction, with the guild or user ID as value.
- class discord_http.message.MessagePin(pinned_at, message)¶
Bases:
NamedTupleRepresents a pinned message in a channel.
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- class discord_http.message.MessageReaction(*, state, message, data)¶
Bases:
objectRepresents a reaction to a message.
- Parameters:
state (DiscordAPI)
message (Message)
data (dict)
- emoji: EmojiParser¶
The emoji that was used for the reaction.
- async fetch_users(*, type=ReactionType.normal, after=None, limit=100) AsyncIterator[User]¶
Fetch users who reacted with this emoji.
- Parameters:
- Yields:
An async iterator of users who reacted with this emoji.
- Yields:
Users who reacted with this emoji.
- Return type:
- class discord_http.message.MessageReference(*, state, data)¶
Bases:
objectRepresents a reference to a message.
- Parameters:
state (DiscordAPI)
data (dict)
- property type: MessageReferenceType¶
The type of the message reference.
- property guild: Guild | PartialGuild | None¶
The guild the message was sent in.
- property channel: PartialChannel | None¶
The channel the message was sent in.
- property message: PartialMessage | None¶
The message if a message_id and channel_id is available.
- class discord_http.message.MessageSnapshot(*, state, data)¶
Bases:
objectRepresents a snapshot of a message, used for message forwarding.
- Parameters:
state (DiscordAPI)
data (dict)
- type: MessageType¶
The type of the message.
- attachments: list[Attachment]¶
The attachments of the message.
- stickers: list[PartialSticker]¶
The stickers of the message.
- class discord_http.message.PartialMessage(*, state, id, channel_id, guild_id=None)¶
Bases:
PartialBaseRepresents a partial message object.
- Parameters:
state (DiscordAPI)
id (int)
channel_id (int)
guild_id (int | None)
- property channel: BaseChannel | PartialChannel¶
The channel the message was sent in.
- property guild: Guild | PartialGuild | None¶
The guild the message was sent in.
- async expire_poll() Message¶
Immediately end the poll, then returns new Message object.
This can only be done if you created it
- Return type:
- async fetch_poll_voters(answer, after=None, limit=100) AsyncIterator[User]¶
Fetch the users who voted for this answer.
- Parameters:
- Yields:
User object of people who voted
- Return type:
- async edit(*, content=<MISSING>, embed=<MISSING>, embeds=<MISSING>, view=<MISSING>, attachment=<MISSING>, attachments=<MISSING>, allowed_mentions=<MISSING>, flags=<MISSING>) Message¶
Edit the message.
- Parameters:
attachments (
list[File] |None) – New attachments of the messageallowed_mentions (
AllowedMentions|None) – Allowed mentions of the messageflags (
MessageFlags|None) – Flags of the message
- Return type:
- Returns:
The edited message
- async forward(*, channel_id) Message¶
Forwards the message to another channel.
This does not accept any normal message parameters, only channel ID.
- async reply(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, view=<MISSING>, tts=False, flags=<MISSING>, allowed_mentions=<MISSING>, stickers=<MISSING>, nonce=<MISSING>, enforce_nonce=False, shared_client_theme=<MISSING>, delete_after=None) Message¶
Sends a reply to a message in a channel.
- Parameters:
tts (
bool|None) – If the message should be sent as a TTS messagetype – The type of response to the message
allowed_mentions (
AllowedMentions|None) – The allowed mentions for the messagestickers (
list[PartialSticker|Snowflake|int] |None) – Stickers from the guild to send with the message, max 3nonce (
int|str|None) – Nonce to verify the message was sent, max 25 charactersenforce_nonce (
bool) – Whether the nonce should be enforced, returning the existing message if it was already sentshared_client_theme (
SharedClientTheme|None) – Client theme to share with the messagedelete_after (
float|None) – If provided, the message will be deleted after the given number of secondsflags (
MessageFlags|None) – Message flags to send with the message
- Return type:
- Returns:
The message object
- async create_public_thread(name, *, auto_archive_duration=60, rate_limit_per_user=None, reason=None) PublicThread¶
Create a public thread from the message.
- Parameters:
- Return type:
- Returns:
The created thread
- Raises:
If auto_archive_duration is not 60, 1440, 4320 or 10080 - If rate_limit_per_user is not between 0 and 21600 seconds
- class discord_http.message.Poll(*, text, allow_multiselect=False, duration=None)¶
Bases:
objectRepresents a poll in a message.
- answers: list[PollAnswer]¶
The list of answers in the poll.
- add_answer(*, text=None, emoji=None) PollAnswer¶
Add an answer to the poll.
- Parameters:
emoji (
EmojiParser|str|None) – The emoji of the answer
- Return type:
- remove_answer(answer_id) None¶
Remove an answer from the poll.
- Parameters:
answer_id (
PollAnswer|int) – The ID to the answer to remove- Raises:
If the answer ID does not exist - If the answer is not a PollAnswer or integer
- Return type:
- class discord_http.message.PollAnswer(*, id, text=None, emoji=None)¶
Bases:
objectRepresents an answer in a poll.
- Parameters:
id (int)
text (str | None)
emoji (EmojiParser | str | None)
- emoji: EmojiParser | str | None¶
The emoji of the answer, if available.
- class discord_http.message.RoleSubscriptionData(role_subscription_listing_id, tier_name, total_months_subscribed, is_renewal)¶
Bases:
NamedTupleRepresents the role subscription data of a message.
- Parameters:
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
Bases:
objectRepresents a custom client theme shared via a message.
- Parameters:
The colors of the theme.
The direction of the theme colors, between 0 and 360.
The intensity of the theme colors, between 0 and 100.
The base mode of the theme, if any.
The shared client theme as a dictionary.
- Return type:
Creates a SharedClientTheme from a dict provided by Discord.
- Return type:
Self- Parameters:
data (dict)
- class discord_http.message.WebhookMessage(*, state, data, application_id, token)¶
Bases:
MessageRepresents a message sent by a webhook.
- Parameters:
state (DiscordAPI)
data (dict)
application_id (int)
token (str)
- property activity: MessageActivity | None¶
The Rich Presence activity of the message, if any.
- property application: Application | None¶
The Rich Presence application of the message, if any.
- attachments: list[Attachment]¶
The attachments of the message.
- call: MessageCall | None¶
The call associated with the message, if any.
- property channel: BaseChannel | PartialChannel¶
The channel the message was sent in.
- property channel_mentions: list[BaseChannel | PartialChannel]¶
The channel mentions in the message.
Can return full channel object if guild and channel cache is enabled
- async create_public_thread(name, *, auto_archive_duration=60, rate_limit_per_user=None, reason=None) PublicThread¶
Create a public thread from the message.
- Parameters:
- Return type:
- Returns:
The created thread
- Raises:
If auto_archive_duration is not 60, 1440, 4320 or 10080 - If rate_limit_per_user is not between 0 and 21600 seconds
- property emojis: list[EmojiParser]¶
The emojis in the message.
- property escaped_content: str¶
Same as content, but with markdown characters escaped, showing the message as it was written.
- async expire_poll() Message¶
Immediately end the poll, then returns new Message object.
This can only be done if you created it
- Return type:
- async fetch_poll_voters(answer, after=None, limit=100) AsyncIterator[User]¶
Fetch the users who voted for this answer.
- Parameters:
- Yields:
User object of people who voted
- Return type:
- property flags: MessageFlags¶
The flags of the message.
- async forward(*, channel_id) Message¶
Forwards the message to another channel.
This does not accept any normal message parameters, only channel ID.
- property guild: Guild | PartialGuild | None¶
The guild the message was sent in.
- interaction: MessageInteraction | None¶
The interaction associated with the message, if any.
- property pretty_content: str¶
Same as content, but mentions are parsed if possible.
User, role and channel mentions are replaced with their names, slash command mentions with /command, mentions that can not be resolved are left as-is.
- reactions: list[MessageReaction]¶
The reactions to the message.
- reference: MessageReference | None¶
The reference to another message, if any.
- async reply(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, view=<MISSING>, tts=False, flags=<MISSING>, allowed_mentions=<MISSING>, stickers=<MISSING>, nonce=<MISSING>, enforce_nonce=False, shared_client_theme=<MISSING>, delete_after=None) Message¶
Sends a reply to a message in a channel.
- Parameters:
tts (
bool|None) – If the message should be sent as a TTS messagetype – The type of response to the message
allowed_mentions (
AllowedMentions|None) – The allowed mentions for the messagestickers (
list[PartialSticker|Snowflake|int] |None) – Stickers from the guild to send with the message, max 3nonce (
int|str|None) – Nonce to verify the message was sent, max 25 charactersenforce_nonce (
bool) – Whether the nonce should be enforced, returning the existing message if it was already sentshared_client_theme (
SharedClientTheme|None) – Client theme to share with the messagedelete_after (
float|None) – If provided, the message will be deleted after the given number of secondsflags (
MessageFlags|None) – Message flags to send with the message
- Return type:
- Returns:
The message object
- resolved_forward: list[MessageSnapshot]¶
The resolved forward messages, if any.
- property role_mentions: list[Role | PartialRole]¶
The role mentions in the message.
Can return full role object if guild and role cache is enabled
- role_subscription_data: RoleSubscriptionData | None¶
The role subscription data of the message, if any.
The client theme shared via the message, if any.
- stickers: list[PartialSticker]¶
The stickers of the message.
- type: MessageType¶
The type of the message.
- async edit(*, content=<MISSING>, embed=<MISSING>, embeds=<MISSING>, attachment=<MISSING>, attachments=<MISSING>, view=<MISSING>, flags=<MISSING>, allowed_mentions=<MISSING>) WebhookMessage¶
Edit the webhook message.
- Parameters:
attachments (
list[File] |None) – Attachments of the messageallowed_mentions (
AllowedMentions|None) – Allowed mentions of the messageflags (
MessageFlags|None) – Flags of the message
- Return type:
- Returns:
The edited message