Message

discord_http.message module

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

Bases: object

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

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

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

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

Bases: object

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

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.

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

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

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