Message

discord_http.message module

class discord_http.message.Attachment(*, state, data)

Bases: object

Represents an attachment in a message.

Parameters:
id: int

The ID of the attachment.

filename: str

The name of the file.

size: int

The size of the file in bytes.

url: str

The URL to the attachment.

proxy_url: str

The proxied URL to the attachment.

flags: AttachmentFlags

The flags of the attachment.

content_type: str | None

The content type of the attachment, if available.

title: str | None

The title of the attachment, if available.

description: str | None

The description of the attachment, if available.

height: int | None

The height of the attachment, if applicable.

width: int | None

The width of the attachment, if applicable.

ephemeral: bool

Whether the attachment is ephemeral or not.

duration_secs: int | None

The duration of the attachment in seconds, if applicable.

waveform: str | None

The waveform of the attachment, if applicable.

is_spoiler() bool

Whether the attachment is a spoiler or not.

Return type:

bool

is_voice_message() bool

bool: Whether this attachment is a voice message.

Return type:

bool

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:

bytes

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.

Parameters:
  • path (str) – Path to save the file to, which includes the filename and extension. Example:

  • use_cached (bool) – Whether to use the cached URL or not, defaults to False

Return type:

int

Returns:

The amount of bytes written to the file

async to_file(*, filename=<MISSING>, spoiler=False) File

Convert the attachment to a sendable File object for Message.send().

Parameters:
  • filename (str | None) – Filename for the file, if empty, the attachment’s filename will be used

  • spoiler (bool) – Weather the file should be marked as a spoiler or not, defaults to False

Return type:

File

Returns:

The attachment as a File object

to_dict() dict

The attachment as a dictionary.

Return type:

dict

class discord_http.message.JumpURL(*, state, url=None, guild_id=None, channel_id=None, message_id=None)

Bases: object

Represents a jump URL to a message.

Parameters:
channel_id: int | None

The ID of the channel the message was sent in.

guild_id: int | None

The ID of the guild the message was sent in, if applicable.

message_id: int | None

The ID of the message, if applicable.

property guild: Guild | PartialGuild | None

The guild the message was sent in.

async fetch_guild() Guild

Returns the guild the message was sent in.

Return type:

Guild

property channel: BaseChannel | PartialChannel | None

Returns 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:

BaseChannel

property message: PartialMessage | None

Returns the message if a message_id is available.

async fetch_message() Message

Returns the message if a message_id is available.

Return type:

Message

property url: str

Returns the jump URL.

class discord_http.message.Message(*, state, data, guild=None)

Bases: PartialMessage

Represents a message object.

Parameters:
async add_reaction(emoji) None

Add a reaction to the message.

Parameters:

emoji (str) – Emoji to add to the message

Return type:

None

property channel: BaseChannel | PartialChannel

Returns the channel the message was sent in.

channel_id: int

The ID of 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:
  • name (str) – Name of the thread

  • auto_archive_duration (int | None) – Duration in minutes to automatically archive the thread after recent activity,

  • rate_limit_per_user (timedelta | int | None) – A per-user rate limit for this thread (0-21600 seconds, default 0)

  • reason (str | None) – Reason for creating the thread

Return type:

PublicThread

Returns:

The created thread

Raises:

ValueError

  • If auto_archive_duration is not 60, 1440, 4320 or 10080 - If rate_limit_per_user is not between 0 and 21600 seconds

property created_at: datetime

The datetime of the snowflake.

async delete(*, delay=None, reason=None) None

Delete the message.

Parameters:
  • delay (float | None) – How many seconds it should wait in background to delete

  • reason (str | None) – Reason for deleting the message (Only applies when deleting messages not made by yourself)

Return type:

None

async edit(*, content=<MISSING>, embed=<MISSING>, embeds=<MISSING>, view=<MISSING>, attachment=<MISSING>, attachments=<MISSING>, allowed_mentions=<MISSING>, flags=<MISSING>) Message

Edit the message.

Parameters:
Return type:

Message

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:

Message

Returns:

The message object of the poll

async fetch() Message

Returns the message object.

Return type:

Message

async fetch_poll_voters(answer, after=None, limit=100) AsyncIterator[User]

Fetch the users who voted for this answer.

Parameters:
  • answer (PollAnswer | int) – The answer to fetch the voters from

  • after (Snowflake | int | None) – The user ID to start fetching from

  • limit (int | None) – The amount of users to fetch, defaults to 100. None will fetch all users.

Yields:

User – User object of people who voted

Return type:

AsyncIterator[User]

async forward(*, channel_id) Message

Forwards the message to another channel.

This does not accept any normal message parameters, only channel ID.

Parameters:

channel_id (Snowflake | int) – Channel ID to forward the message to

Return type:

Message

Returns:

The message object

property guild: Guild | PartialGuild | None

Returns the guild the message was sent in.

guild_id: int | None

The ID of the guild the message was sent in, if applicable.

id: int

The ID of the snowflake.

async pin(*, reason=None) None

Pin the message.

Parameters:

reason (str | None) – Reason for pinning the message

Return type:

None

async publish() Message

Crosspost the message to another channel.

Return type:

Message

async remove_all_reactions() None

Remove all reactions from the message.

Return type:

None

async remove_reaction(emoji, *, user_id=None) None

Remove a reaction from the message.

Parameters:
  • emoji (str) – Emoji to remove from the message

  • user_id (int | None) – User ID to remove the reaction from

Return type:

None

async reply(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, view=<MISSING>, tts=False, flags=<MISSING>, allowed_mentions=<MISSING>, delete_after=None) Message

Sends a reply to a message in a channel.

Parameters:
  • content (str | None) – Cotnent of the message

  • embed (Embed | None) – Includes an embed object

  • embeds (list[Embed] | None) – List of embed objects

  • file (File | None) – A file object

  • files (list[File] | None) – A list of file objects

  • view (View | None) – Send components to the message

  • tts (bool | None) – If the message should be sent as a TTS message

  • type – The type of response to the message

  • allowed_mentions (AllowedMentions | None) – The allowed mentions for the message

  • delete_after (float | None) – If provided, the message will be deleted after the given number of seconds

  • flags (MessageFlags | None) – Message flags to send with the message

Return type:

Message

Returns:

The message object

async unpin(*, reason=None) None

Unpin the message.

Parameters:

reason (str | None) – Reason for unpinning the message

Return type:

None

type: MessageType

The type of the message.

content: str

The content of the message.

author: User | Member

The author of the message.

pinned: bool

Whether the message is pinned or not.

mention_everyone: bool

Whether the message mentions everyone or not.

tts: bool

Whether the message is a TTS message or not.

poll: Poll | None

The poll associated with the message, if any.

embeds: list[Embed]

The embeds of the message.

attachments: list[Attachment]

The attachments of the message.

stickers: list[PartialSticker]

The stickers of the message.

reactions: list[MessageReaction]

The reactions to the message.

mentions: list[Member | User]

The mentions in the message.

view: View | None

The components of the message, if any.

edited_timestamp: datetime | None

The timestamp of when the message was last edited, if available.

reference: MessageReference | None

The reference to another message, if any.

resolved_reply: Message | None

The resolved reply to the message, if any.

resolved_forward: list[MessageSnapshot]

The resolved forward messages, if any.

interaction: MessageInteraction | None

The interaction associated with the message, if any.

is_system() bool

Returns whether the message is a system message.

Return type:

bool

property emojis: list[EmojiParser]

Returns the emojis in the message.

property jump_url: JumpURL

Returns the jump URL of the message.

property role_mentions: list[Role | PartialRole]

Returns the role mentions in the message.

Can return full role object if guild and role cache is enabled

property channel_mentions: list[BaseChannel | PartialChannel]

Returns the channel mentions in the message.

Can return full role object if guild and channel cache is enabled

property jump_urls: list[JumpURL]

Returns the jump URLs in the message.

class discord_http.message.MessageInteraction(*, state, data)

Bases: PartialBase

Represents a message interaction.

Parameters:
name: str | None

The name of the interaction, if available.

user: User

The user who triggered the interaction.

property type: InteractionType

The type of the interaction.

property created_at: datetime

The datetime of the snowflake.

id: int

The ID of the snowflake.

class discord_http.message.MessageReaction(*, state, message, data)

Bases: object

Represents a reaction to a message.

Parameters:
count: int

The number of users that reacted with this emoji.

me: bool

Whether the bot has reacted with this emoji.

emoji: EmojiParser

The emoji that was used for the reaction.

me_burst: bool

Whether the bot has reacted with this emoji in burst mode.

burst_me: bool

Whether the bot has reacted with this emoji in burst mode.

burst_count: int

The number of users that reacted with this emoji in burst mode.

burst_colors: list[Colour]

The colors of the burst reaction.

async add() None

Make the bot react with this emoji.

Return type:

None

async remove(*, user_id=None) None

Remove the reaction from the message.

Parameters:

user_id (int | None) – User ID to remove the reaction from If none provided, it will remove the reaction from the bot

Return type:

None

async fetch_users(*, type=ReactionType.normal, after=None, limit=100) AsyncIterator[User]

Fetch users who reacted with this emoji.

Parameters:
  • type (ReactionType | int) – The type of reaction to fetch, by default ReactionType.normal

  • after (Snowflake | int | None) – The ID of the last user to fetch, by default None

  • limit (int | None) – The maximum number of users to fetch, by default 100

Return type:

AsyncIterator[User]

Returns:

An async iterator of users who reacted with this emoji.

Yields:

Users who reacted with this emoji.

class discord_http.message.MessageReference(*, state, data)

Bases: object

Represents a reference to a message.

Parameters:
guild_id: int | None

The ID of the guild the message was sent in, if applicable.

channel_id: int | None

The ID of the channel the message was sent in.

message_id: int | None

The ID of the message, if applicable.

property type: MessageReferenceType

The type of the message reference.

property jump_url: JumpURL

The jump URL of the message.

property guild: Guild | PartialGuild | None

The guild the message was sent in.

property channel: PartialChannel | None

Returns the channel the message was sent in.

property message: PartialMessage | None

Returns the message if a message_id and channel_id is available.

to_dict() dict

Returns the message reference as a dictionary.

Return type:

dict

class discord_http.message.PartialMessage(*, state, id, channel_id, guild_id=None)

Bases: PartialBase

Represents a partial message object.

Parameters:
channel_id: int

The ID of the channel the message was sent in.

guild_id: int | None

The ID of the guild the message was sent in, if applicable.

property channel: BaseChannel | PartialChannel

Returns the channel the message was sent in.

property guild: Guild | PartialGuild | None

Returns the guild the message was sent in.

property jump_url: JumpURL

Returns the jump URL of the message, GuildID will always be @me.

async fetch() Message

Returns the message object.

Return type:

Message

async delete(*, delay=None, reason=None) None

Delete the message.

Parameters:
  • delay (float | None) – How many seconds it should wait in background to delete

  • reason (str | None) – Reason for deleting the message (Only applies when deleting messages not made by yourself)

Return type:

None

async expire_poll() Message

Immediately end the poll, then returns new Message object.

This can only be done if you created it

Return type:

Message

Returns:

The message object of the poll

async fetch_poll_voters(answer, after=None, limit=100) AsyncIterator[User]

Fetch the users who voted for this answer.

Parameters:
  • answer (PollAnswer | int) – The answer to fetch the voters from

  • after (Snowflake | int | None) – The user ID to start fetching from

  • limit (int | None) – The amount of users to fetch, defaults to 100. None will fetch all users.

Yields:

User – User object of people who voted

Return type:

AsyncIterator[User]

async edit(*, content=<MISSING>, embed=<MISSING>, embeds=<MISSING>, view=<MISSING>, attachment=<MISSING>, attachments=<MISSING>, allowed_mentions=<MISSING>, flags=<MISSING>) Message

Edit the message.

Parameters:
Return type:

Message

Returns:

The edited message

async publish() Message

Crosspost the message to another channel.

Return type:

Message

async forward(*, channel_id) Message

Forwards the message to another channel.

This does not accept any normal message parameters, only channel ID.

Parameters:

channel_id (Snowflake | int) – Channel ID to forward the message to

Return type:

Message

Returns:

The message object

async reply(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, view=<MISSING>, tts=False, flags=<MISSING>, allowed_mentions=<MISSING>, delete_after=None) Message

Sends a reply to a message in a channel.

Parameters:
  • content (str | None) – Cotnent of the message

  • embed (Embed | None) – Includes an embed object

  • embeds (list[Embed] | None) – List of embed objects

  • file (File | None) – A file object

  • files (list[File] | None) – A list of file objects

  • view (View | None) – Send components to the message

  • tts (bool | None) – If the message should be sent as a TTS message

  • type – The type of response to the message

  • allowed_mentions (AllowedMentions | None) – The allowed mentions for the message

  • delete_after (float | None) – If provided, the message will be deleted after the given number of seconds

  • flags (MessageFlags | None) – Message flags to send with the message

Return type:

Message

Returns:

The message object

async pin(*, reason=None) None

Pin the message.

Parameters:

reason (str | None) – Reason for pinning the message

Return type:

None

async unpin(*, reason=None) None

Unpin the message.

Parameters:

reason (str | None) – Reason for unpinning the message

Return type:

None

async add_reaction(emoji) None

Add a reaction to the message.

Parameters:

emoji (str) – Emoji to add to the message

Return type:

None

property created_at: datetime

The datetime of the snowflake.

id: int

The ID of the snowflake.

async remove_reaction(emoji, *, user_id=None) None

Remove a reaction from the message.

Parameters:
  • emoji (str) – Emoji to remove from the message

  • user_id (int | None) – User ID to remove the reaction from

Return type:

None

async remove_all_reactions() None

Remove all reactions from the message.

Return type:

None

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:
  • name (str) – Name of the thread

  • auto_archive_duration (int | None) – Duration in minutes to automatically archive the thread after recent activity,

  • rate_limit_per_user (timedelta | int | None) – A per-user rate limit for this thread (0-21600 seconds, default 0)

  • reason (str | None) – Reason for creating the thread

Return type:

PublicThread

Returns:

The created thread

Raises:

ValueError

  • 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: object

Represents a poll in a message.

Parameters:
text: str | None

The question text of the poll.

allow_multiselect: bool

Whether the poll allows multiple answers to be selected.

answers: list[PollAnswer]

The list of answers in the poll.

duration: int | None

The duration of the poll in hours, if applicable.

layout_type: int

The layout type of the poll, currently only 1 is available.

expiry: datetime | None

The expiry time of the poll, if applicable.

is_finalized: bool

Whether the poll is finalized or not.

add_answer(*, text=None, emoji=None) PollAnswer

Add an answer to the poll.

Parameters:
Return type:

PollAnswer

remove_answer(answer_id) None

Remove an answer from the poll.

Parameters:

answer_id (PollAnswer | int) – The ID to the answer to remove

Raises:

ValueError

  • If the answer ID does not exist - If the answer is not a PollAnswer or integer

Return type:

None

to_dict() dict

The poll as a dictionary.

Return type:

dict

classmethod from_dict(data) Self

Create a poll from a dictionary.

Return type:

Self

Parameters:

data (dict)

class discord_http.message.WebhookMessage(*, state, data, application_id, token)

Bases: Message

Represents a message sent by a webhook.

Parameters:
async add_reaction(emoji) None

Add a reaction to the message.

Parameters:

emoji (str) – Emoji to add to the message

Return type:

None

attachments: list[Attachment]

The attachments of the message.

author: User | Member

The author of the message.

property channel: BaseChannel | PartialChannel

Returns the channel the message was sent in.

channel_id: int

The ID of the channel the message was sent in.

property channel_mentions: list[BaseChannel | PartialChannel]

Returns the channel mentions in the message.

Can return full role object if guild and channel cache is enabled

content: str

The content of the message.

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:
  • name (str) – Name of the thread

  • auto_archive_duration (int | None) – Duration in minutes to automatically archive the thread after recent activity,

  • rate_limit_per_user (timedelta | int | None) – A per-user rate limit for this thread (0-21600 seconds, default 0)

  • reason (str | None) – Reason for creating the thread

Return type:

PublicThread

Returns:

The created thread

Raises:

ValueError

  • If auto_archive_duration is not 60, 1440, 4320 or 10080 - If rate_limit_per_user is not between 0 and 21600 seconds

property created_at: datetime

The datetime of the snowflake.

edited_timestamp: datetime | None

The timestamp of when the message was last edited, if available.

embeds: list[Embed]

The embeds of the message.

property emojis: list[EmojiParser]

Returns the emojis in the 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:

Message

Returns:

The message object of the poll

async fetch() Message

Returns the message object.

Return type:

Message

async fetch_poll_voters(answer, after=None, limit=100) AsyncIterator[User]

Fetch the users who voted for this answer.

Parameters:
  • answer (PollAnswer | int) – The answer to fetch the voters from

  • after (Snowflake | int | None) – The user ID to start fetching from

  • limit (int | None) – The amount of users to fetch, defaults to 100. None will fetch all users.

Yields:

User – User object of people who voted

Return type:

AsyncIterator[User]

async forward(*, channel_id) Message

Forwards the message to another channel.

This does not accept any normal message parameters, only channel ID.

Parameters:

channel_id (Snowflake | int) – Channel ID to forward the message to

Return type:

Message

Returns:

The message object

property guild: Guild | PartialGuild | None

Returns the guild the message was sent in.

guild_id: int | None

The ID of the guild the message was sent in, if applicable.

id: int

The ID of the snowflake.

interaction: MessageInteraction | None

The interaction associated with the message, if any.

is_system() bool

Returns whether the message is a system message.

Return type:

bool

property jump_url: JumpURL

Returns the jump URL of the message.

property jump_urls: list[JumpURL]

Returns the jump URLs in the message.

mention_everyone: bool

Whether the message mentions everyone or not.

mentions: list[Member | User]

The mentions in the message.

async pin(*, reason=None) None

Pin the message.

Parameters:

reason (str | None) – Reason for pinning the message

Return type:

None

pinned: bool

Whether the message is pinned or not.

poll: Poll | None

The poll associated with the message, if any.

async publish() Message

Crosspost the message to another channel.

Return type:

Message

reactions: list[MessageReaction]

The reactions to the message.

reference: MessageReference | None

The reference to another message, if any.

async remove_all_reactions() None

Remove all reactions from the message.

Return type:

None

async remove_reaction(emoji, *, user_id=None) None

Remove a reaction from the message.

Parameters:
  • emoji (str) – Emoji to remove from the message

  • user_id (int | None) – User ID to remove the reaction from

Return type:

None

async reply(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, view=<MISSING>, tts=False, flags=<MISSING>, allowed_mentions=<MISSING>, delete_after=None) Message

Sends a reply to a message in a channel.

Parameters:
  • content (str | None) – Cotnent of the message

  • embed (Embed | None) – Includes an embed object

  • embeds (list[Embed] | None) – List of embed objects

  • file (File | None) – A file object

  • files (list[File] | None) – A list of file objects

  • view (View | None) – Send components to the message

  • tts (bool | None) – If the message should be sent as a TTS message

  • type – The type of response to the message

  • allowed_mentions (AllowedMentions | None) – The allowed mentions for the message

  • delete_after (float | None) – If provided, the message will be deleted after the given number of seconds

  • flags (MessageFlags | None) – Message flags to send with the message

Return type:

Message

Returns:

The message object

resolved_forward: list[MessageSnapshot]

The resolved forward messages, if any.

resolved_reply: Message | None

The resolved reply to the message, if any.

property role_mentions: list[Role | PartialRole]

Returns the role mentions in the message.

Can return full role object if guild and role cache is enabled

stickers: list[PartialSticker]

The stickers of the message.

tts: bool

Whether the message is a TTS message or not.

type: MessageType

The type of the message.

async unpin(*, reason=None) None

Unpin the message.

Parameters:

reason (str | None) – Reason for unpinning the message

Return type:

None

view: View | None

The components of the message, if any.

application_id

The ID of the application that created the webhook.

token

The token of the webhook, used for editing and deleting 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:
Return type:

WebhookMessage

Returns:

The edited message

async delete(*, delay=None, reason=None) None

Delete the webhook message.

Parameters:
  • delay (float | None) – How many seconds it should wait in background to delete.

  • reason (str | None) – Reason for deleting the message.

Return type:

None