Melisa Models Message#

Color#

Color#

class Color[source]#

Bases: object

Represents a Discord colour. This class is similar to a (red, green, blue) tuple.

value#

The raw integer colour value.

Type:

int

property b#

Returns the blue component of the colour.

Type:

int

classmethod default()[source]#

A factory method that returns a Colour with a value of 0.

classmethod from_hex_code(hex_code, /)[source]#

Convert the given hexadecimal color code to a Color.

The inputs may be of the following format (case insensitive): 1a2, #1a2, 0x1a2 (for web-safe colors), or 1a2b3c, #1a2b3c, 0x1a2b3c (for regular 3-byte color-codes).

Parameters:

hex_code (str) – A hexadecimal color code to parse. This may optionally start with a case insensitive 0x or #.

Returns:

A corresponding Color object.

Return type:

Color

Raises:

ValueError – If hex_code is not a hexadecimal or is a invalid length.

classmethod from_rgb(r, g, b)[source]#

Constructs a Colour from an RGB tuple.

property g#

Returns the green component of the colour.

Type:

int

property r#

Returns the red component of the colour.

Type:

int

to_rgb()[source]#
Tuple[int, int, int]:

Returns an (r, g, b) tuple representing the colour.

Embed#

Embed#

class Embed[source]#

Bases: APIModelBase

Represents an embed sent in with message within Discord.

title#

Title of embed

Type:

Optional[str]

type#

Type of embed (always “rich” for webhook embeds)

Type:

Optional[EmbedType]

description#

Description of embed

Type:

Optional[str]

color#

Color code of the embed. If you really want to do something with a color, feel free to convert it to the Color:

color = Color(embed.color)
Type:

Optional[int]

fields#

Fields information.

Type:

Optional[List[EmbedField]]

footer#

Footer information.

Type:

Optional[EmbedFooter]

image#

Image information.

Type:

Optional[EmbedImage]

provider#

Provider information.

Type:

Optional[EmbedProvider]

thumbnail#

Thumbnail information.

Type:

Optional[EmbedThumbnail]

timestamp#

Timestamp of embed content

Type:

Optional[Timestamp]

url#

Url of embed

Type:

Optional[str]

video#

Video information.

Type:

Optional[EmbedVideo]

add_field(name, value, *, inline=False)[source]#

Adds a field to the embed object.

This function returns the class instance to allow for fluent-style chaining.

Parameters:
  • name (str) – The name of the field.

  • value (str) – The value of the field.

  • inline (bool) – Whether the field should be displayed inline.

Returns:

This embed.

Return type:

Embed

clear_fields()[source]#

Removes all fields from this embed.

edit_field(index, *, name=<UNDEFINED>, value=<UNDEFINED>, inline=<UNDEFINED>)[source]#

Edit an existing field on this embed.

Parameters:
  • index (int) – The index of the field to edit.

  • name (Optional[str]) – The name of the field.

  • value (Optional[str]) – The value of the field.

  • inline (Optional[bool]) – Whether the field should be displayed inline.

Returns:

This embed.

Return type:

Embed

Raises:

IndexError – Raised if the index is greater than len(embed.fields) - 1 or less than -len(embed.fields)

classmethod from_dict(data)[source]#

Generate a message from the given data.

Parameters:

data (dict) – The dictionary to convert into an unknown channel.

remove_field(index)[source]#

Remove an existing field from this embed.

Parameters:

index (int) – The index of the embed field to remove.

Returns:

This embed.

Return type:

Embed

Raises:

IndexError – Raised if the index is greater than len(embed.fields) - 1 or less than -len(embed.fields)

set_author(name, *, url=<UNDEFINED>, icon_url=<UNDEFINED>, proxy_icon_url=<UNDEFINED>)[source]#

Set the author for the embed.

Parameters:
  • name (str) – Name of author

  • url (Optional[str]) – Url of author icon (only supports http(s) and attachments)

  • icon_url (Optional[str]) – Url of author

  • proxy_icon_url (Optional[str]) – A proxied url of author icon

Returns:

Updated embed.

Return type:

Embed

set_color(color)[source]#

Sets color in the supported by discord format.

Parameters:

color (Union[Color, int]) – The datetime to set the timestamp to.

Returns:

The new embed object.

Return type:

Embed

Sets the embed footer.

Parameters:
  • text (str) – Footer text

  • icon_url (Optional[str]) – Url of footer icon (only supports http(s) and attachments)

  • proxy_icon_url (Optional[str]) – A proxied url of footer icon

Returns:

Updated embed.

Return type:

Embed

set_image(url, *, proxy_url=<UNDEFINED>)[source]#

Set the image for the embed.

Parameters:
  • url (str) – Source url of image (only supports http(s) and attachments)

  • proxy_url (Optional[str]) – A proxied url of the image

Returns:

Updated embed.

Return type:

Embed

set_thumbnail(url, *, proxy_url=<UNDEFINED>)[source]#

Set the thumbnail for the embed.

Parameters:
  • url (str) – Source url of thumbnail (only supports http(s) and attachments)

  • proxy_url (Optional[str]) – A proxied url of the thumbnail

Returns:

Updated embed.

Return type:

Embed

set_timestamp(time)[source]#

Sets timestamp in the supported by discord format.

Parameters:

time (Timestamp) – The datetime to set the timestamp to.

Returns:

The new embed object.

Return type:

Embed

total_length()[source]#

Get the total character count of the embed.

Returns:

The total character count of this embed, including title, description, fields, footer, and author combined.

Return type:

int

EmbedType#

class EmbedType[source]#

Bases: Enum

Embed types are “loosely defined” and, for the most part, are not used by our clients for rendering. Embed attributes power what is rendered. Embed types should be considered deprecated and might be removed in a future API version.

RICH#

Generic embed rendered from embed attributes

IMAGE#

Image embed

VIDEO#

Video embed

GIFV#

Animated gif image embed rendered as a video embed

ARTICLE#

Article embed

Link embed

EmbedThumbnail#

class EmbedThumbnail[source]#

Bases: object

Representation of the Embed Thumbnail

url#

Source url of the thumbnail

Type:

str

proxy_url#

A proxied url of the thumbnail

Type:

Optional[str]

height#

Height of the thumbnail

Type:

Optional[int]

width#

Width of the thumbnail

Type:

Optional[int]

EmbedVideo#

class EmbedVideo[source]#

Bases: object

Representation of the Embed Video

url#

Source url of the video

Type:

Optional[str]

proxy_url#

A proxied url of the video

Type:

Optional[str]

height#

Height of the video

Type:

Optional[int]

width#

Width of the video

Type:

Optional[int]

EmbedImage#

class EmbedImage[source]#

Bases: object

Representation of the Embed Image

url#

Source url of image (only supports http(s) and attachments)

Type:

str

proxy_url#

A proxied url of the image

Type:

Optional[str]

height#

Height of the image

Type:

Optional[int]

width#

Width of the image

Type:

Optional[int]

EmbedProvider#

class EmbedProvider[source]#

Bases: object

Representation of the Embed Provider

name#

Name of provider

Type:

Optional[str]

url#

Url of provider

Type:

Optional[str]

EmbedAuthor#

class EmbedProvider[source]#

Bases: object

Representation of the Embed Provider

name#

Name of provider

Type:

Optional[str]

url#

Url of provider

Type:

Optional[str]

EmbedFooter#

class EmbedFooter[source]#

Bases: object

Representation of the Embed Footer

text#

Footer text

Type:

str

icon_url#

Url of footer icon (only supports http(s) and attachments)

Type:

Optional[str]

proxy_icon_url#

A proxied url of footer icon

Type:

Optional[str]

EmbedField#

class EmbedField[source]#

Bases: object

Representation of the Embed Field

name#

Name of the field

Type:

str

value#

Value of the field

Type:

str

inline#

Whether or not this field should display inline

Type:

Optional[bool]

File#

File#

class File[source]#

Bases: object

A parameter object used for sending file objects.

filepath#

A file-like object opened in binary mode and read mode or a filename representing a file in the hard drive to open.

Note

If the file-like object passed is opened via open then the modes ‘rb’ should be used. To pass binary data, consider usage of io.BytesIO.

Type:

Union[os.PathLike, io.BufferedIOBase]

filename#

The filename to display when uploading to Discord. If this is not given then it defaults to fp.name or if filepath is a string then the filename will default to the string given.

Type:

Optional[str]

spoiler#

Whether the attachment is a spoiler.

Type:

bool

Message#

AllowedMentions#

class AllowedMentions[source]#

Bases: object

A class that represents what mentions are allowed in a message.

everyone#

Whether to allow everyone and here mentions. Defaults to True.

Type:

bool

users#

Controls the users being mentioned. If True (the default) then users are mentioned based on the message content. If False then users are not mentioned at all. Or you can specify list of ids.

Type:

Union[bool, List[Snowflake]]

roles#

Controls the roles being mentioned. If True then roles are mentioned based on the message content. If False then roles are not mentioned at all.

Type:

Union[bool, List[Snowflake]]

replied_user#

Whether to mention the author of the message being replied to.

Type:

bool

classmethod disabled()[source]#

A factory method that returns a AllowedMentions with all fields set to False

classmethod enabled()[source]#

A factory method that returns a AllowedMentions with all fields explicitly set to True

MessageType#

class MessageType[source]#

Bases: IntEnum

Message Type NOTE: Type 19 and 20 are only in API v8. In v6, they are still type 0. Type 21 is only in API v9.

MessageActivityType#

class MessageActivityType[source]#

Bases: IntEnum

Message Activity Type

MessageFlags#

class MessageFlags[source]#

Bases: IntEnum

Message Flags

CROSSPOSTED#

This message has been published to subscribed channels (via Channel Following)

IS_CROSSPOST#

This message originated from a message in another channel (via Channel Following)

SUPPRESS_EMBEDS#

Do not include any embeds when serializing this message

SOURCE_MESSAGE_DELETED#

The source message for this crosspost has been deleted (via Channel Following)

URGENT#

This message came from the urgent message system

HAS_THREAD#

This message has an associated thread, with the same id as the message

EPHEMERAL#

This message is only visible to the user who invoked the Interaction

LOADING#

This message is an Interaction Response and the bot is “thinking”

FAILED_TO_MENTION_SOME_ROLES_IN_THREAD#

This message failed to mention some roles and add their members to the thread

Message#

class Message[source]#

Bases: APIModelBase

Represents a message sent in a channel within Discord.

id#

Id of the message

Type:

Snowflake

channel_id#

Id of the channel the message was sent in

Type:

Snowflake

channel#

Object of channel where message was sent in

Type:

Channel

guild#

Object of guild where message was sent in

Type:

Guild

guild_id#

Id of the guild the message was sent in

Type:

Snowflake

author#

The author of this message.

Type:

GuildMember

content#

Contents of the message

Type:

str

timestamp#

When this message was sent

Type:

Timestamp

edited_timestamp#

When this message was edited (or null if never)

Type:

Timestamp

tts#

Whether this was a TTS message

Type:

bool

mention_everyone#

Whether this message mentions everyone

Type:

bool

mentions#

Users specifically mentioned in the message

Type:

typing.Any

mention_roles#

Roles specifically mentioned in this message

Type:

typing.Any

mention_channels#

Channels specifically mentioned in this message

Type:

typing.Any

attachments#

Any attached files

Type:

typing.Any

embeds#

Any embedded content

Type:

typing.Any

reactions#

Reactions to the message

Type:

typing.Any

nonce#

Used for validating a message was sent

Type:

int or str

pinned#

Whether this message is pinned

Type:

bool

webhook_id#

If the message is generated by a webhook, this is the webhook’s id

Type:

Snowflake

type#

Type of message

Type:

MessageType

activity#

Sent with Rich Presence-related chat embeds

Type:

typing.Any

application#

Sent with Rich Presence-related chat embeds

Type:

typing.Any

application_id#

If the message is an Interaction or application-owned webhook, this is the id of the application

Type:

Snowflake

message_reference#

Data showing the source of a crosspost, channel follow add, pin, or reply message

Type:

typing.Any

flags#

Message flags combined as a bitfield

Type:

int

interaction#

Sent if the message is a response to an Interaction

Type:

typing.Any

thread#

The thread that was started from this message, includes thread member object

Type:

typing.Any

components#

Sent if the message contains components like buttons, action rows, or other interactive components

Type:

typing.Any

sticker_items#

Sent if the message contains stickers

Type:

typing.Any

stickers#

Deprecated the stickers sent with the message

Type:

typing.Any

await delete(*, delay=None)[source]#

This function is a coroutine.

Deletes the message.

Parameters:

delay (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the message.

Raises:
  • Forbidden – You do not have proper permissions to delete the message.

  • NotFound – The message was deleted already

  • HTTPException – Deleting the message failed.

classmethod from_dict(data)[source]#

Generate a message from the given data.

Parameters:

data (dict) – The dictionary to convert into an unknown channel.

await pin(*, reason=None)[source]#

This function is a coroutine.

Pins the message.

You must have the MANAGE_MESSAGES permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) – The reason for pinning the message. Shows up on the audit log.

Raises:
  • HTTPException – Pinning the message failed, probably due to the channel having more than 50 pinned messages.

  • ForbiddenError – You do not have permissions to pin the message.

  • NotFound – The message or channel was not found or deleted.

await unpin(*, reason=None)[source]#

This function is a coroutine.

Unpins the message.

You must have the MANAGE_MESSAGES permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) – The reason for unpinning the message. Shows up on the audit log.

Raises:
  • HTTPException – Pinning the message failed, probably due to the channel having more than 50 pinned messages.

  • ForbiddenError – You do not have permissions to unpin the message.

  • NotFound – The message or channel was not found or deleted.