Message

discord_http.message module

class discord_http.message.Attachment(*, state: DiscordAPI, data: dict)[source]

Bases: object

async fetch(*, use_cached: bool = False) bytes[source]

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

Returns:

The attachment as bytes

Return type:

bytes

Raises:

HTTPException – If the request returned anything other than 2XX

is_spoiler() bool[source]

bool: Whether the attachment is a spoiler or not

async save(path: str, *, use_cached: bool = False) int[source]

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: ./path/to/file.png

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

Returns:

The amount of bytes written to the file

Return type:

int

to_dict() dict[source]

dict: The attachment as a dictionary

async to_file(*, filename: str | None = <MISSING>, spoiler: bool = False) File[source]

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

Parameters:
  • filename (Optional[str]) – 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

Returns:

The attachment as a File object

Return type:

File

class discord_http.message.JumpURL(*, state: DiscordAPI, url: str | None = None, guild_id: int | None = None, channel_id: int | None = None, message_id: int | None = None)[source]

Bases: object

property channel: PartialChannel | None

Returns the channel the message was sent in

Type:

PartialChannel

async fetch_channel() BaseChannel[source]

BaseChannel: Returns the channel the message was sent in

async fetch_guild() Guild[source]

Optional[Guild]: Returns the guild the message was sent in

async fetch_message() Message[source]

Message: Returns the message if a message_id is available

property guild: PartialGuild | None

The guild the message was sent in

Type:

Optional[PartialGuild]

property message: PartialMessage | None

Returns the message if a message_id is available

Type:

Optional[PartialMessage]

property url: str

Returns the jump URL

Type:

Optional[str]

class discord_http.message.Message(*, state: DiscordAPI, data: dict, guild: PartialGuild | None = None)[source]

Bases: PartialMessage

property channel_mentions: list[PartialChannel]

Returns the channel mentions in the message

Type:

list[PartialChannel]

property emojis: list[EmojiParser]

Returns the emojis in the message

Type:

list[EmojiParser]

property jump_url: JumpURL

Returns the jump URL of the message

Type:

JumpURL

property jump_urls: list[JumpURL]

Returns the jump URLs in the message

Type:

list[JumpURL]

property role_mentions: list[PartialRole]

Returns the role mentions in the message

Type:

list[PartialRole]

class discord_http.message.MessageReference(*, state: DiscordAPI, data: dict)[source]

Bases: object

property channel: PartialChannel | None

Returns the channel the message was sent in

Type:

Optional[PartialChannel]

property guild: PartialGuild | None

The guild the message was sent in

Type:

Optional[PartialGuild]

property message: PartialMessage | None

Returns the message if a message_id and channel_id is available

Type:

Optional[PartialMessage]

to_dict() dict[source]

dict: Returns the message reference as a dictionary

class discord_http.message.PartialMessage(*, state: DiscordAPI, id: int, channel_id: int)[source]

Bases: PartialBase

async add_reaction(emoji: str) None[source]

Add a reaction to the message

Parameters:

emoji (str) – Emoji to add to the message

property channel: PartialChannel

Returns the channel the message was sent in

Type:

PartialChannel

async create_public_thread(name: str, *, auto_archive_duration: int | None = 60, rate_limit_per_user: timedelta | int | None = None, reason: str | None = None) PublicThread[source]

Create a public thread from the message

Parameters:
  • name (str) – Name of the thread

  • auto_archive_duration (Optional[int]) – Duration in minutes to automatically archive the thread after recent activity,

  • rate_limit_per_user (Optional[Union[timedelta, int]]) – A per-user rate limit for this thread (0-21600 seconds, default 0)

  • reason (Optional[str]) – Reason for creating the thread

Returns:

The created thread

Return type:

PublicThread

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(*, reason: str | None = None) None[source]

Delete the message

async edit(*, content: str | None = <MISSING>, embed: ~discord_http.embeds.Embed | None = <MISSING>, embeds: list[~discord_http.embeds.Embed] | None = <MISSING>, view: ~discord_http.view.View | None = <MISSING>, attachment: ~discord_http.file.File | None = <MISSING>, attachments: list[~discord_http.file.File] | None = <MISSING>, allowed_mentions: ~discord_http.mentions.AllowedMentions | None = <MISSING>) Message[source]

Edit the message

Parameters:
  • content (Optional[str]) – Content of the message

  • embed (Optional[Embed]) – Embed of the message

  • embeds (Optional[list[Embed]]) – Embeds of the message

  • view (Optional[View]) – Components of the message

  • attachment (Optional[File]) – New attachment of the message

  • attachments (Optional[list[File]]) – New attachments of the message

  • allowed_mentions (Optional[AllowedMentions]) – Allowed mentions of the message

Returns:

The edited message

Return type:

Message

async expire_poll() Message[source]

Immediately end the poll, then returns new Message object. This can only be done if you created it

Returns:

The message object of the poll

Return type:

Message

async fetch() Message[source]

Message: Returns the message object

async fetch_poll_voters(answer: PollAnswer | int, after: Snowflake | int | None = None, limit: int | None = 100) AsyncIterator[User][source]

Fetch the users who voted for this answer

Parameters:
  • answer (Union[PollAnswer, int]) – The answer to fetch the voters from

  • after (Optional[Union[Snowflake, int]]) – The user ID to start fetching from

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

Yields:

User – User object of people who voted

property jump_url: JumpURL

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

Type:

JumpURL

async pin(*, reason: str | None = None) None[source]

Pin the message

Parameters:

reason (Optional[str]) – Reason for pinning the message

async publish() Message[source]

Crosspost the message to another channel.

async remove_reaction(emoji: str, *, user_id: int | None = None) None[source]

Remove a reaction from the message

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

  • user_id (Optional[int]) – User ID to remove the reaction from

async reply(content: str | None = <MISSING>, *, embed: ~discord_http.embeds.Embed | None = <MISSING>, embeds: list[~discord_http.embeds.Embed] | None = <MISSING>, file: ~discord_http.file.File | None = <MISSING>, files: list[~discord_http.file.File] | None = <MISSING>, view: ~discord_http.view.View | None = <MISSING>, tts: bool | None = False, allowed_mentions: ~discord_http.mentions.AllowedMentions | None = <MISSING>) Message[source]

Sends a reply to a message in a channel.

Parameters:
  • content (Optional[str]) – Cotnent of the message

  • embed (Optional[Embed]) – Includes an embed object

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

  • file (Optional[File]) – A file object

  • files (Union[list[File], File]) – A list of file objects

  • view (View) – Send components to the message

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

  • type (Optional[ResponseType]) – The type of response to the message

  • allowed_mentions (Optional[AllowedMentions]) – The allowed mentions for the message

Returns:

The message object

Return type:

Message

async unpin(*, reason: str | None = None) None[source]

Unpin the message

Parameters:

reason (Optional[str]) – Reason for unpinning the message

class discord_http.message.Poll(*, text: str, allow_multiselect: bool = False, duration: timedelta | int | None = None)[source]

Bases: object

add_answer(*, text: str | None = None, emoji: EmojiParser | str | None = None) PollAnswer[source]

Add an answer to the poll

Parameters:
  • text (Optional[str]) – The text of the answer

  • emoji (Optional[Union[EmojiParser, str]]) – The emoji of the answer

classmethod from_dict(data: dict) Self[source]
remove_answer(answer_id: PollAnswer | int) None[source]

Remove an answer from the poll

Parameters:

answer (Union[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

to_dict() dict[source]
class discord_http.message.WebhookMessage(*, state: DiscordAPI, data: dict, application_id: int, token: str)[source]

Bases: Message

async delete(*, reason: str | None = None) None[source]

Delete the webhook message

Parameters:

reason (Optional[str]) – Reason for deleting the message

async edit(*, content: str | None = <MISSING>, embed: ~discord_http.embeds.Embed | None = <MISSING>, embeds: list[~discord_http.embeds.Embed] | None = <MISSING>, attachment: ~discord_http.file.File | None = <MISSING>, attachments: list[~discord_http.file.File] | None = <MISSING>, view: ~discord_http.view.View | None = <MISSING>, allowed_mentions: ~discord_http.mentions.AllowedMentions | None = <MISSING>) WebhookMessage[source]

Edit the webhook message

Parameters:
  • content (Optional[str]) – Content of the message

  • embed (Optional[Embed]) – Embed of the message

  • embeds (Optional[list[Embed]]) – Embeds of the message

  • attachment (Optional[File]) – Attachment of the message

  • attachments (Optional[list[File]]) – Attachments of the message

  • view (Optional[View]) – Components of the message

  • allowed_mentions (Optional[AllowedMentions]) – Allowed mentions of the message

Returns:

The edited message

Return type:

WebhookMessage