Skip to main content

Message

Represents a message from Discord.

Attributes

id
int
The message ID.
content
str
The actual contents of the message.
author
Member | User
A Member that sent the message. If channel is a private channel or the user has left the guild, then it is a User instead.
channel
TextChannel | Thread | DMChannel | GroupChannel
The TextChannel or Thread that the message was sent from. Could be a DMChannel or GroupChannel if it’s a private message.
guild
Guild | None
The guild that the message belongs to, if applicable.
created_at
datetime
The message’s creation time in UTC.
edited_at
datetime | None
An aware UTC datetime object containing the edited time of the message.
tts
bool
Specifies if the message was done with text-to-speech. This can only be accurately received in on_message due to a Discord limitation.
type
MessageType
The type of message. In most cases this should not be checked, but it is helpful in cases where it might be a system message.
mention_everyone
bool
Specifies if the message mentions everyone.
This does not check if the @everyone or @here text is in the message itself. Rather this boolean indicates if either the @everyone or the @here text is in the message and it did end up mentioning.
mentions
list[User | Member]
A list of Member that were mentioned. If the message is in a private message then the list will be of User instead.
The order of the mentions list is not in any particular order, so you should not rely on it. This is a Discord limitation.
channel_mentions
list[GuildChannel]
A list of GuildChannel that were mentioned. If the message is in a private message then the list is always empty.
role_mentions
list[Role]
A list of Role that were mentioned. If the message is in a private message then the list is always empty.
embeds
list[Embed]
A list of embeds the message has.
attachments
list[Attachment]
A list of attachments given to a message.
reactions
list[Reaction]
Reactions to a message. Reactions can be either custom emoji or standard unicode emoji.
pinned
bool
Specifies if the message is currently pinned.
flags
MessageFlags
Extra features of the message.
reference
MessageReference | None
The message that this message references. This is only applicable to messages of type MessageType.pins_add, crossposted messages created by a followed channel integration, or message replies.
stickers
list[StickerItem]
A list of sticker items given to the message.
components
list[Component]
A list of components in the message.
thread
Thread | None
The thread created from this message, if applicable.
jump_url
str
Returns a URL that allows the client to jump to this message.
poll
Poll | None
The poll associated with this message, if applicable.

Methods

Replies to the message.
content
str
The content of the message to send.
embed
Embed
The rich embed for the content.
mention_author
bool
Whether to mention the author of the message being replied to. Defaults to True.
view
View
A Discord UI View to add to the message.
Returns: Message - The message that was sent.Example:
await message.reply("Thanks for your message!")
Edits the message.
The message must be authored by the bot user.
content
str
The new content to replace the message with.
embed
Embed
The new embed to replace the original with.
embeds
list[Embed]
The new embeds to replace the original with. Must be a maximum of 10.
attachments
list[Attachment]
A list of attachments to keep in the message. If [] is passed then all attachments are removed.
view
View
The updated view to update this message with.
Returns: Message - The newly edited message.Example:
await message.edit(content="Updated content")
Deletes the message.
delay
float
If provided, the number of seconds to wait before deleting the message.
Example:
await message.delete()
await message.delete(delay=5.0)  # Delete after 5 seconds
Adds a reaction to the message.
emoji
Emoji | PartialEmoji | str
required
The emoji to react with.
Example:
await message.add_reaction("👍")
await message.add_reaction(custom_emoji)
Removes a reaction by the member from the message.
emoji
Emoji | PartialEmoji | str
required
The emoji to remove.
member
Member | User
required
The member whose reaction to remove.
Example:
await message.remove_reaction("👍", member)
Removes all reactions from the message.
You need the manage_messages permission to use this.
Example:
await message.clear_reactions()
Pins the message.
You must have the manage_messages permission to do this.
reason
str
The reason for pinning the message. Shows up on the audit log.
Example:
await message.pin(reason="Important announcement")
Unpins the message.
You must have the manage_messages permission to do this.
reason
str
The reason for unpinning the message. Shows up on the audit log.
Example:
await message.unpin()
Creates a thread from this message.
name
str
required
The name of the thread.
auto_archive_duration
int
The duration in minutes before a thread is automatically archived for inactivity.
slowmode_delay
int
Specifies the slowmode rate limit for users in this thread, in seconds.
Returns: Thread - The created thread.Example:
thread = await message.create_thread(name="Discussion")
await thread.send("Let's discuss this!")
Creates a MessageReference from the current message.Returns: MessageReference - The reference to this message.Example:
reference = message.to_reference()
await channel.send("Reply", reference=reference)

Attachment

Represents an attachment from Discord.

Attributes

id
int
The attachment ID.
filename
str
The attachment’s filename.
url
str
The attachment URL. If the message this attachment was attached to is deleted, then this will 404.
size
int
The attachment size in bytes.
height
int | None
The attachment’s height, in pixels. Only applicable to images and videos.
width
int | None
The attachment’s width, in pixels. Only applicable to images and videos.
content_type
str | None
The attachment’s media type.
description
str | None
The attachment’s description.

Methods

Saves this attachment into a file-like object.
fp
BufferedIOBase | PathLike
required
The file-like object to save this attachment to or the filename to use.
seek_begin
bool
Whether to seek to the beginning of the file after saving.
Returns: int - The number of bytes written.Example:
await attachment.save('downloaded_file.png')
Retrieves the content of this attachment as a bytes object.Returns: bytes - The contents of the attachment.Example:
data = await attachment.read()
Converts the attachment into a File suitable for sending via send().Returns: File - The attachment as a file suitable for sending.Example:
file = await attachment.to_file()
await channel.send(file=file)
Whether this attachment contains a spoiler.Returns: bool - True if the filename starts with “SPOILER_”.

Build docs developers (and LLMs) love