Message

discord_http.message module

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

Bases: object

Represents an attachment in a message.

Parameters:
id

The ID of the attachment.

Type:

int

filename

The name of the file.

Type:

str

size

The size of the file in bytes.

Type:

int

url

The URL to the attachment.

Type:

str

proxy_url

The proxied URL to the attachment.

Type:

str

ephemeral

Whether the attachment is ephemeral or not.

Type:

bool

flags

The flags of the attachment.

Type:

AttachmentFlags

content_type

The content type of the attachment, if available.

Type:

str | None

title

The title of the attachment, if available.

Type:

str | None

description

The description of the attachment, if available.

Type:

str | None

height

The height of the attachment, if applicable.

Type:

int | None

width

The width of the attachment, if applicable.

Type:

int | None

duration_secs

The duration of the attachment in seconds, if applicable.

Type:

int | None

waveform

The waveform of the attachment, if applicable.

Type:

str | None

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

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

to_dict() dict

The attachment as a dictionary.

Return type:

dict

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

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

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

Type:

int | None

channel_id

The ID of the channel the message was sent in.

Type:

int | None

message_id

The ID of the message, if applicable.

Type:

int | None

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

async fetch_guild() Guild

Returns the guild the message was sent in.

Return type:

Guild

async fetch_message() Message

Returns the message if a message_id is available.

Return type:

Message

property guild: Guild | PartialGuild | None

The guild the message was sent in.

property message: PartialMessage | None

Returns the message if a message_id is available.

property url: str

Returns the jump URL.

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

Bases: PartialMessage

Represents a message object.

Parameters:
type

The type of the message.

Type:

MessageType

content

The content of the message.

Type:

str

author

The author of the message.

Type:

User | Member

pinned

Whether the message is pinned or not.

Type:

bool

mention_everyone

Whether the message mentions everyone or not.

Type:

bool

tts

Whether the message is a TTS message or not.

Type:

bool

poll

The poll associated with the message, if any.

Type:

Poll | None

embeds

The embeds of the message.

Type:

list[Embed]

attachments

The attachments of the message.

Type:

list[Attachment]

stickers

The stickers of the message.

Type:

list[PartialSticker]

reactions

The reactions to the message.

Type:

list[MessageReaction]

mentions

The mentions in the message.

Type:

list[Member | User]

view

The components of the message, if any.

Type:

View | None

edited_timestamp

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

Type:

datetime | None

reference

The reference to another message, if any.

Type:

MessageReference | None

resolved_reply

The resolved reply to the message, if any.

Type:

Message | None

resolved_forward

The resolved forward messages, if any.

Type:

list[MessageSnapshot]

interaction

The interaction associated with the message, if any.

Type:

MessageInteraction | None

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 emojis: list[EmojiParser]

Returns the emojis in the message.

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.

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

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

Bases: PartialBase

Represents a message interaction.

Parameters:
type

The type of the interaction.

Type:

InteractionType

name

The name of the interaction, if available.

Type:

str | None

user

The user who triggered the interaction.

Type:

User

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

Bases: object

Represents a reaction to a message.

Parameters:
count

The number of users that reacted with this emoji.

Type:

int

burst_count

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

Type:

int

me

Whether the bot has reacted with this emoji.

Type:

bool

emoji

The emoji that was used for the reaction.

Type:

EmojiParser

me_burst

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

Type:

bool

burst_me

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

Type:

bool

burst_count

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

Type:

int

burst_colors

The colors of the burst reaction.

Type:

list[Colour]

async add() None

Make the bot react with this emoji.

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.

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

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

Bases: object

Represents a reference to a message.

Parameters:
type

The type of the message reference.

Type:

MessageReferenceType

guild_id

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

Type:

int | None

channel_id

The ID of the channel the message was sent in.

Type:

int | None

message_id

The ID of the message, if applicable.

Type:

int | None

property channel: PartialChannel | None

Returns the channel the message was sent in.

property guild: Guild | PartialGuild | None

The guild the message was sent in.

property jump_url: JumpURL

The jump URL of the message.

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

The ID of the channel the message was sent in.

Type:

int

guild_id

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

Type:

int | 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 channel: BaseChannel | PartialChannel

Returns 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

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.

property jump_url: JumpURL

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

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, allowed_mentions=<MISSING>) 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

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

class discord_http.message.Poll(*, text, allow_multiselect=False, duration=None)

Bases: object

Represents a poll in a message.

Parameters:
text

The question text of the poll.

Type:

str | None

allow_multiselect

Whether the poll allows multiple answers to be selected.

Type:

bool

answers

The list of answers in the poll.

Type:

list[PollAnswer]

duration

The duration of the poll in hours, if applicable.

Type:

int | None

layout_type

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

Type:

int

expiry

The expiry time of the poll, if applicable.

Type:

datetime | None

is_finalized

Whether the poll is finalized or not.

Type:

bool

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

Add an answer to the poll.

Parameters:
Return type:

PollAnswer

classmethod from_dict(data) Self

Create a poll from a dictionary.

Return type:

Self

Parameters:

data (dict)

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

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

Bases: Message

Represents a message sent by a webhook.

Parameters:
application_id

The ID of the application that created the webhook.

Type:

int

token

The token of the webhook, used for editing and deleting the message.

Type:

str

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

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