API Reference#

The full discord.io API Reference.

Version Specific Details#

There is currently 2 ways to get version info

The easiest is via __version__

discord.__version__#

A string representation of the version. e.g. '0.3.0'. This is based off of PEP 440.

And second is by using version_info

discord.version_info#

A named tuple that is similar to sys.version_info.

Just like sys.version_info the valid values for releaselevel are ‘alpha’, ‘beta’, ‘candidate’ and ‘final’.

REST API#

class discord.RESTClient(*, state=None, proxy=None, proxy_auth=None, version=10)[source]#

Represents a Rest connection with Discord.

New in version 0.3.0.

url#

The Discord API URL

loop#

The current event loop or your own.

connector#

The base aiohttp connector

header#

The header sent to discord.

async send(route: discord.api.rest.Route, files: Optional[Sequence[discord.file.File]] = None, form: Optional[Iterable[discord.types.dict.Dict]] = None, **params: Any)[source]#

Sends a request to discord

New in version 0.3.0.

class discord.RESTFactory(*, state: Optional[discord.state.ConnectionState] = None, proxy: Optional[str] = None, proxy_auth: Optional[str] = None, version=10)[source]#

The RESTFactory for most requests.

New in version 0.3.0.

rest#

The RESTClient.

Gateway’s#

class discord.Shard(state: discord.state.ConnectionState, dispatcher: discord.internal.dispatcher.Dispatcher, shard_id: int, url: str, mobile: bool = False)[source]#

Represents a Discord Shard.

Parameters

:param mobile bool: If to have a mobile presence or not.

buffer#

An array of bytes which buffers the connection.

remaining#

The amount remaining

per#

The times per

window#

The window

max#

The max

inflator#

The inflator for this shard.

async block() None[source]#

A function to block the connection tempoarily

async connect(token: str) None[source]#

Connects to the url specified, with the token

Parameters

token – Your bot token.

_session#

The aiohttp ClientSession

ws#

The WebSocket connection.

delay() float[source]#

A float showing how long we should delay until retrying.

property is_ratelimited: bool#

Returns a True if this shard is ratelimited and False if it isn’t

async send(data: discord.types.dict.Dict) None[source]#

Send a request to the Gateway via the shard

:param data Dict: The data to send

class discord.Gateway(state: discord.state.ConnectionState, dispatcher: discord.internal.dispatcher.Dispatcher, factory: discord.http.core.RESTFactory, mobile: bool = False)[source]#

Represents a Gateway connection with Discord.

Parameters
async connect(token: str) None[source]#

Connects to the url specified, with the token

Parameters

token – Your bot token.

_session#

The aiohttp ClientSession

ws#

The WebSocket connection.

async send(data: Dict) Coroutine[Any, Any, None][source]#

Send a request to the Gateway via the shard

:param data Dict: The data to send

class discord.VoiceGateway(state: discord.state.ConnectionState, guild_id: int, hook)[source]#

Opus#

class discord.Encoder[source]#

A class used to encode .pcm data into opus data for the discord voice gateway

Voice#

class discord.VoiceClient(state: discord.state.ConnectionState, channel: discord.channels.VoiceChannel)[source]#

Used to interact with the discord voice api

Parameters

Client#

class discord.Client(intents: Optional[int] = 28924, module: Optional[str] = 'discord', shards: Optional[int] = None, mobile: Optional[bool] = False, proxy: Optional[str] = None, proxy_auth: Optional[str] = None, logs: Union[None, int, str, Dict] = None, debug: Optional[bool] = False, state: Optional[discord.state.ConnectionState] = None, chunk_guild_members: Optional[bool] = False, api_version: Optional[int] = 10)[source]#

Represents a Discord bot.

New in version 0.4.0.

factory#

The instance of RESTFactory

state#

The client’s connection state

dispatcher#

The dispatcher

gateway#

The Gateway

p#

The presence

cogs#

A dict of all Cogs.

intents#

Your current Gateway intents.

Type

int

Parameters
  • token – The bot token

  • intents – The bot intents, defaults 32509

  • status – The bot status, defaults to online

  • afk – If the bot is afk, default to False

  • loop – The loop you want to use, defaults to asyncio.new_event_loop

  • module – The module with a banner.txt to print

  • voice – If to enable the voice gateway or not, defaults False.

  • logs – A int, str or dict.

  • debug – To show debug logs or not.

  • state (ConnectionState) – Allow’s for custom ConnectionStates, and soforth custom db caches.

  • command_prefix (str) – The prefix for prefixed commands, defaults to ‘’.

  • chunk_guild_members – If to cache guild members, this allows the before argument on member events, aswell as faster fetching times.

  • api_version (int) – The Discord API Version to use, normally defaults to the newest version.

change_presence(name: str, type: int, status: Literal['online', 'dnd', 'idle', 'invisible', 'offline'] = 'online', stream_url: Optional[str] = None, afk: Optional[bool] = False, shard: Optional[int] = None)[source]#

Changes the bot’s presence

Parameters
  • name – The presence name

  • type – The presence type

  • status

    The presence status

    Note

    can be ‘online’, ‘dnd’, invisable and offline.

  • stream_url – Used with the streaming presence type

  • afk – If to be afk or not

async connect(token: str)[source]#

Starts the WebSocket(Gateway) connection with Discord.

New in version 0.4.0.

create_button(label: str, callback: Coroutine[Any, Any, discord.internal.dispatcher.T], style: Literal[1, 2, 3, 4, 5] = 1, custom_id: Optional[str] = None, url: Optional[str] = None)[source]#

Creates a button

Parameters
  • label – The button label

  • callback – The button callback

  • style – The button style to use

  • custom_id – A custom_id

  • url

    A url

    Note

    can only be used in buttons

event(coro: Coroutine[Any, Any, discord.internal.dispatcher.T]) Coroutine[Any, Any, discord.internal.dispatcher.T][source]#

Register an event

fetch_guild(guild_id)[source]#

Fetches the guild from the cache

Parameters

guild_id (int) – The guild to fetch

Return type

Guild

async get_guild(guild_id)[source]#

Gets a guild by requesting to the API

Parameters

guild_id (int) – The guild to get

Return type

Guild

property is_ready#

Returns if the bot is ready or not.

listen(name: Optional[str] = None) Callable[[discord.client.CFT], discord.client.CFT][source]#

Listen to a event

like Client.event() but you can have a event split into multiple coroutines.

Parameters

name – The event to listen to

async login(token: str)[source]#

Starts the bot connection

New in version 0.4.0.

run(token: str, **kwargs)[source]#

A blocking function to start your bot

Parameters
  • token (str) – Your bot token

  • asyncio_debug (bool) –

slash_command(name: Optional[str] = None, options: Optional[List[dict]] = None, guild_ids: Optional[List[int]] = None, default_permission: bool = True)[source]#

Creates a slash command

Parameters
  • name (str) – The slash command name

  • callback – The slash command callback

  • options (List) – A list of slash command options

  • guild_ids (List[int]) – A list of guild ids

  • description (str) – The application command description

  • default_permission (bool) – If this slash command should have default permissions

property user#

Returns the bot user

Return type

User

Webhook#

class discord.WebhookAdapter(state)[source]#

The base class for interperting Webhooks

New in version 0.3.0.

Parameters
  • id – The webhook id

  • token – The webhook token

rest#

An instance of RESTClient.

delete_message(id, token, message: int)[source]#

Deletes a message

Parameters

message – The message to delete

delete_webhook(id, token)[source]#

Deletes the Webhook

edit_message(id, token, message: int, content: Optional[str] = None, allowed_mentions: Optional[bool] = None)[source]#

Edits a Webhook message

Parameters
  • message – The Message ID

  • content – Change the content

  • allowed_mentions – A allowed mentions object

execute(id, token, content: Optional[str] = None, username: Optional[str] = None, avatar_url: Optional[str] = None, tts: Optional[bool] = None, allowed_mentions: Optional[bool] = None, embed: Optional[discord.embed.Embed] = None, embeds: Optional[List[discord.embed.Embed]] = None, flags: Optional[Any] = None, files: Optional[Sequence[discord.file.File]] = None)[source]#

Execute the Webhook

Parameters
  • content (str) – The content to send.

  • username (str) – The username the Webhook should have

  • avatar_url (str) – The avatar the Webhook should have

  • tts (bool) – If the message should have tts enabled

  • allowed_mentions – A allowed mentions object

fetch_message(id, token, message: int)[source]#

Fetches a Webhook message.

fetch_webhook(id, token)[source]#

Fetch the current Webhook from the API.

modify_webhook(id, token, name: Optional[str] = None, avatar: Optional[str] = None)[source]#

Modify the Webhook

Parameters
  • name – Change the name

  • avatar – Change the avatar

class discord.Webhook(state)[source]#

The base class for interperting Webhooks

New in version 0.3.0.

Parameters
  • id – The webhook id

  • token – The webhook token

rest#

An instance of RESTClient.

execute(id, token, content: Optional[str] = None, username: Optional[str] = None, avatar_url: Optional[str] = None, tts: Optional[bool] = None, allowed_mentions: Optional[bool] = None, embed: Optional[discord.embed.Embed] = None, embeds: Optional[List[discord.embed.Embed]] = None, flags: Optional[Any] = None, files: Optional[Sequence[discord.file.File]] = None)[source]#

Execute the Webhook

Parameters
  • content (str) – The content to send.

  • username (str) – The username the Webhook should have

  • avatar_url (str) – The avatar the Webhook should have

  • tts (bool) – If the message should have tts enabled

  • allowed_mentions – A allowed mentions object

Colors#

class discord.Color(value: int)[source]#

Represents the default discord colors

Defines factory methods which return a certain color code to be used.

New in version 0.7.0.

classmethod blue() int[source]#

A factory color method which returns 0x3498DB

classmethod blurple() int[source]#

A factory color method which returns 0x5865F2

classmethod brand_green() int[source]#

A factory color method which returns 0x57F287

classmethod brand_red() int[source]#

A factory color method which returns 0xED4245

classmethod dark_blue() int[source]#

A factory color method which returns 0x206694

classmethod dark_gold() int[source]#

A factory color method which returns 0xC27C0E

classmethod dark_gray() int[source]#

A factory color method which returns 0x607D8B

classmethod dark_green() int[source]#

A factory color method which returns 0x1F8B4C

classmethod dark_magenta() int[source]#

A factory color method which returns 0xAD1457

classmethod dark_orange() int[source]#

A factory color method which returns 0xA84300

classmethod dark_purple() int[source]#

A factory color method which returns 0x71368A

classmethod dark_red() int[source]#

A factory color method which returns 0x992D22

classmethod dark_teal() int[source]#

A factory color method which returns 0x11806A

classmethod dark_theme() int[source]#

A factory color method which returns 0x2F3136

classmethod default() int[source]#

A factory color method which returns 0

classmethod from_hex(hex_code: str)[source]#

A factory color method which gets its color from a hex code string

classmethod from_rgb(red: int, green: int, blue: int) int[source]#

A factory color method which gets its color from rgb values

classmethod fushia() int[source]#

A factory color method which returns 0xEB459E

classmethod gold() int[source]#

A factory color method which returns 0xF1C40F

classmethod green() int[source]#

A factory color method which returns 0x2ECC71

classmethod light_gray() int[source]#

A factory color method which returns 0x979C9F

classmethod magenta() int[source]#

A factory color method which returns 0xE91E63

classmethod orange() int[source]#

A factory color method which returns 0xE67E22

classmethod purple() int[source]#

A factory color method which returns 0x9b59b6

classmethod red() int[source]#

A factory color method which returns 0xE74C3C

classmethod teal() int[source]#

A factory color method which returns 0x1ABC9C

classmethod yellow() int[source]#

A factory color method which returns 0xFEE75C

class discord.Colour(value: int)[source]#

Represents the default discord colours

Defines factory methods which return a certain colour code to be used.

New in version 0.7.0.

Dispatcher#

class discord.Dispatcher(state: discord.state.ConnectionState)[source]#

Dispatches raw and non-raw events

Parameters

state – The ConnectionState

Types#

class discord.Message(msg: dict, app)[source]#

Represents a Discord Message

New in version 0.6.0.

Parameters
  • msg – The message in dict format

  • app – The current Client

from_dict#

A dict object of the message

content#

The message content in string format

channel#

The channel where the message happened

property author: discord.user.User#

Returns the User of the message

Return type

User

property channel#

Returns the channel which this message took place in.

Return type

TextChannel

edit(content: Optional[str] = None, embeds: Optional[List[discord.embed.Embed]] = None, embed: Optional[discord.embed.Embed] = None, flags: Optional[int] = None, allowed_mentions: Optional[discord.types.allowed_mentions.MentionObject] = None, components: Optional[List[dict]] = None, files: Optional[Sequence[discord.file.File]] = None, attachments: Optional[List[discord.assets.Attachment]] = None)[source]#

Edits the current message

fetch_guild() discord.guild.Guild[source]#

Returns the Guild of the message

Return type

Guild

property id: int#

Returns the message id

Return type

int

async reply(content: Optional[str] = None, files: Optional[Sequence[discord.file.File]] = None, embed: Optional[discord.embed.Embed] = None, embeds: Optional[List[discord.embed.Embed]] = None, tts: Optional[bool] = False, allowed_mentions: Optional[discord.types.allowed_mentions.MentionObject] = None, components: Optional[List[Dict[str, Any]]] = None, component: Optional[Dict[str, Any]] = None)[source]#

Replys to the current message

Parameters
  • content – The message content

  • files – The message files

  • embed – A Embed

  • embeds – A list of Embed

  • tts – A bool of if tts should be on in this message

  • allowed_mentions – A allowed mentions object

  • components – A list of components

async send(content: Optional[str] = None, files: Optional[Sequence[discord.file.File]] = None, embed: Optional[discord.embed.Embed] = None, embeds: Optional[List[discord.embed.Embed]] = None, tts: Optional[bool] = False, allowed_mentions: Optional[discord.types.allowed_mentions.MentionObject] = None, components: Optional[List[Dict[str, Any]]] = None, component=None)[source]#

Sends a message to the channel currently active in

Parameters
  • content – The message content

  • files – The message files

  • embed – A Embed

  • embeds – A list of Embed

  • tts – A bool of if tts should be on in this message

  • allowed_mentions – A allowed mentions object

  • components – A list of components

class discord.User(usr: dict)[source]#

Represents a Discord User

New in version 0.6.0.

Parameters

usr – The user in dict format

property bot: bool#

If the User is a bot or not

Return type

bool

discriminator() int[source]#

The users discriminator id

Return type

int

property id: int#

The users snowflake id

Return type

int

public_flags()[source]#

The users public flags.

username() str[source]#

The users username

Return type

str

class discord.Member(data: Dict, guild: Union[int, Any], factory: discord.http.core.RESTFactory)[source]#

Represents a Discord Guild Member

New in version 0.7.0.

Parameters
  • data – The member data, a dict

  • factory – The current instance of RESTFactory

from_dict#

The raw dict object of the Member.

ban(delete_message_days: int = 0, reason: Optional[str] = None)[source]#

Bans the member

Parameters
  • delete_message_days (Optional[int]) – The amount of days to delete messages for

  • reason (Optional[str]) – A reason why you are banning this member

communication_disabled_until() str[source]#

Gives the time communication is disabled

Return type

str

deaf() bool[source]#

Returns a bool if the member is deaf in a voice channel or not.

Return type

bool

edit(nick: Optional[str] = None, roles: Optional[List[int]] = None, mute: Optional[bool] = False, deaf: Optional[bool] = False, channel_id: Optional[int] = None, timeout: Optional[str] = None, reason: Optional[str] = None) None[source]#

Edits the member

Parameters
  • nick (Optional[str]) – Change the members nickname

  • roles (Optional[list`[:class:`int]]) – Chaneg the members roles

  • mute (Optional[bool]) – If the member should be muted

  • deaf (Optional[bool]) – If the member should be deafend

  • channel_id (Optional[int]) – The channel id to move the member to

  • timeout (Optional[str]) – Set a timeout for the member, has to be a ISO8601 timestanp

  • reason (Optional[str]) – A reason why you are editing this member

Returns

joined_at() str[source]#

Gives a timestamp of when the member joined the server

Return type

str

kick(reason: Optional[str] = None)[source]#

Kicks the member

Parameters

reason (Optional[str]) – A reason why you are kicking this member

mute() bool[source]#

Returns if the member it muted from a channel

Return type

bool

nick() str[source]#

Returns the members nick name, if any

Returns

pending() bool[source]#

Returns if the user is pending verification or not

Return type

bool

permissions() Dict[str, Any][source]#

Returns a dict of the users permissions

Return type

dict

premium_since() str[source]#

Gives a timestamp of when the member started boosting

Returns

property user#

Returns the members User object

Return type

User

Guild#

class discord.Guild(guild: Dict, rest_factory)[source]#

Represents a Discord Guild.

New in version 0.6.0.

Parameters
  • guild – The raw guild object

  • rest_factory – The current RESTFactory

async change_voice_state(*, channel: Optional[int] = None, self_mute: Optional[bool] = False, self_deaf: Optional[bool] = False)[source]#

Changes the bot’s voice state in a guild

New in version 0.8.0.

Parameters
  • channel (int) – The channel to connect to, None if to disconnect.

  • self_mute – Should the bot be muted?

  • self_deaf – Should the bot be deaf?

discovery_splash() str[source]#

The discovery splash, if None returns None

Return type

str

emojis() List[discord.assets.Emoji][source]#

A list of Emoji

Return type

list[Emoji]

async get_ban(user_id: int)[source]#

Gets a ban for a user

Parameters

user_id (int) – The user id to get the ban for

Return type

Ban

async get_bans()[source]#

Gives a list of Ban

Return type

List[Ban]

async get_channels()[source]#

Gives a list of Channel objects

Return type

List[Union[TextChannel, VoiceChannel, Category, DMChannel, GroupDMChannel, Thread]]

async get_member(id: int)[source]#

Gets a member and returns a Member object

Parameters

id – The members id

Return type

Member

property id: int#

The guild id

Return type

int

leave()[source]#

Leaves the guild

splash() str[source]#

The splash screen, if None returns None

Return type

str

sub_count() int[source]#

The subscription count, returns a int

Return type

int

vanity() str[source]#

The vanity url, if None returns None

Return type

str

class discord.Role(data: Dict, factory)[source]#

Represents a Discord Role

New in version 0.8.0.

Parameters

data (dict) – The raw role data

property color: int#

Returns the roles color

Return type

int

give_to(user_id: int, reason: Optional[str] = None)[source]#

Gives a user the role

hoist() bool[source]#

If the role is hoisted or not

Return type

bool

icon(format: Optional[discord.enums.FormatType] = '.png') str[source]#

Gives the role icon’s link, if any.

Return type

str

property id: int#

Gives the snowflake id of the role

Return type

int

managed() bool[source]#

If the role is managed or not

Return type

bool

mentionable() bool[source]#

If the role is publicly mentionable

Return type

bool

property name: str#

Gives the name of the role

Return type

str

permissions() str[source]#

Gives the role permissions

Return type

str

property position: int#

Gives the current role position

Return type

int

remove_from(user_id: int, reason: Optional[str] = None)[source]#

Removes a user from the role

tags() str[source]#

The current role’ tags

Return type

str

unicode_emoji() str[source]#

Gives the roles unicode emoji

Return type

str

class discord.ScheduledEvent(data: Dict, factory)[source]#

Represents a Discord Guild Scheduled Event

New in version 0.8.0.

Parameters

data (dict) – The raw event data

channel_id() Optional[int][source]#

Gives the scheduled events current channel, if any

Returns

property creator: discord.user.User#

Gives a User of the creator of this scheduled event

Return type

User

property description: str#

Gives the description of the scheduled event

Return type

str

end_time() Union[None, str][source]#

Gives the endtime of the scheduled event

Returns

entity_id() int[source]#

Gives the current entity id

Return type

int

guild_id() int[source]#

Gives the scheduled event’ current guild

Return type

int

property id: int#

Gives the scheduled events snowflake id

Return type

int

image(format: discord.enums.FormatType = '.png')[source]#

Gives the url of the scheduled event’ banner

Return type

str

joined() int[source]#

Gives the amount of users which joined the event

Return type

int

property metadata: discord.guild.ScheduledEventMetadata#

Gives the scheduled event metadata

Return type

ScheduledEventMetadata

property name: str#

Gives the scheduled event’ name

Return type

str

start_time() str[source]#

Gives the start time of the scheduled event

Return type

str

status() discord.enums.ScheduledEventStatusType[source]#

Gives the current event’ status

Return type

int

type() discord.enums.ScheduledEventType[source]#

Gives the type of scheduled event

Return type

int

class discord.ScheduledEventMetadata(data: Dict)[source]#

Represents a Discord Scheduled event metadata

New in version 0.8.0.

Parameters

data (dict) – The raw metadata’ data

property location: Optional[str]#

Gives the location the event is happening in

Returns

class discord.WelcomeScreen(data: Dict, factory)[source]#

Represents a Discord Guild WelcomeScreen

New in version 0.8.0.

Parameters

data (dict) –

channels() List[discord.guild.WelcomeChannel][source]#

Gives a list of WelcomeChannel

Return type

list[WelcomeChannel]

property description: str#

Gives the WelcomeScreen’ description

Return type

str

class discord.WelcomeChannel(data: Dict)[source]#

Represents a Discord WelcomeScreen Channel

New in version 0.8.0.

Parameters

data (dict) – The raw WelcomeChannel data

property channel_id: int#

Gives the Channel’ id

Return type

int

property description: str#

Gives the description of the channel

Return type

str

emoji_id() Optional[int][source]#

Gives the Emoji id, if any

Returns

emoji_name() Optional[str][source]#

Gives the Emoji name, if any

Returns

Assets#

class discord.Emoji(data: Dict)[source]#

Represents a Discord Emoji.

New in version 0.8.0.

Parameters

data – The raw emoji data

from_dict#

The raw emoji data

from_dict#

The data in dict format.

class discord.PartialEmoji(data: Optional[dict] = None, id: Optional[int] = None, name: Optional[str] = None, animated: Optional[bool] = False)[source]#

Represents a Partial Discord Emoji

New in version 1.0.

Parameters
  • data (Optional[dict]) – The raw emoji data

  • id (int) – The emoji id

  • name (str) – The emoji name

  • animated (bool) – If the emoji is animated

class discord.Sticker(data: dict, state: discord.state.ConnectionState)[source]#

Represents a Discord Sticker.

New in version 0.8.0.

Parameters
from_dict#

The raw Sticker data

class discord.Attachment(data: dict)[source]#

Represents a Discord Attachment

New in version 0.8.0.

Parameters

data (dict) – The raw attachment data

property description: str#

Gives the attachments description

Return type

str

height() int[source]#

Gives the height of the attachment

Return type

int

property id: int#

Gives the attachment’ id

Return type

int

invisable() bool[source]#

If the attachment is normally seeable or not

Return type

bool

property name: str#

Gives the attachments name

Return type

str

proxy_url() str[source]#

Gives the proxied url of the attachment

Return type

str

size() int[source]#

Gives the size of the attachment

Return type

int

type() str[source]#

Gives the content type, i.e ‘image/png’ or ‘image/jpeg’

Return type

str

url() str[source]#

Gives the attachment’ url

Return type

str

width() int[source]#

Gives the width of the attachment

Return type

int

Channels#

class discord.Category(data: Dict, state: discord.state.ConnectionState)[source]#

Represents a Discord Category

New in version 0.8.0.

Parameters
  • data (dict) – The raw category data

  • state (state) – The connection state

guild_id() int[source]#

Gives the guild’ snowflake id

Return type

int

property id: int#

Gives the snowflake id of the channel

Return type

int

property name: str#

Gives the name of the category

Return type

str

permission_overwrites() List[Union[int, str]][source]#

Gives a list of permission overwrites

Returns

property position: int#

Gives the category position

Return type

int

class discord.TextChannel(data: Dict, state: discord.state.ConnectionState)[source]#

Represents a Discord Text Channel

Parameters
category_id() int[source]#

Gives the id of the category this channel is in

Return type

int

property guild#

The guild this channel is in

Return type

Guild

property guild_id: int#

Gives the guild id of the channel

Return type

int

property id: int#

Gives the channel’ id

Return type

int

last_message_id() int[source]#

Gives the snowflake id of the last message

Return type

int

property name: str#

Gives the name of the channel

Return type

str

property nsfw: bool#

If the channel is nsfw

Return type

bool

permission_overwrites() List[Union[int, str]][source]#

Gives the permission overwrites of the channel

property position: int#

Gives the position of the channel

Return type

int

topic() str[source]#

Gives the channel’ topic

Return type

str

class discord.VoiceChannel(data: Dict, state: discord.state.ConnectionState)[source]#

Represents a Discord Voice Channel

New in version 0.8.0.

Parameters
property guild#

The guild this channel is in

Return type

Guild

property id: int#

Gives the Voice Channel’ Snowflake ID

Return type

int

property name: str#

The name of the voice channel

Return type

str

property position: int#

The voice channel’ position

Return type

int

class discord.DMChannel(data: Dict, state: discord.state.ConnectionState)[source]#

Represents a Discord DM Channel

New in version 0.8.0.

Parameters
property id: int#

The snowflake id of the channel

Return type

int

last_message_id() int[source]#

The snowflake id of the last message

Return type

int

recipients()[source]#

The list of users in the channel

Return type

List[User]

class discord.GroupDMChannel(data: Dict, state: discord.state.ConnectionState)[source]#

Represents a Discord Group DM Channel

New in version 0.8.0.

Parameters

data (dict) –

icon(format: discord.enums.FormatType = '.png') str[source]#

Gives the link of the channel’ icon

Return type

str

name() str[source]#

Gives the name of the Group DM

Return type

str

owner() discord.user.User[source]#

Returns the User which is the owner of this Group DM

Return type

User

class discord.Thread(data: Dict, state: discord.state.ConnectionState)[source]#

Represents a Discord Thread

New in version 0.8.0.

Parameters
property channel_id: int#

The channel id of the thread

Return type

int

property guild_id: int#

The guild id of the thread

Return type

int

property id: int#

The thread’ snowflake id

Return type

int

last_message_id() int[source]#

Gives the last message id in the thread

Return type

int

member_count() int[source]#

Gives the thread’ member count

Return type

int

message_count() int[source]#

Gives the amount of messages in the thread

Return type

int

property metadata: discord.channels.ThreadMetadata#

Gives the thread’ metadata

Return type

ThreadMetadata

property name: str#

Gives the name of the thread

Return type

str

property owner_id: int#

Gives the owner id of the Thread

Return type

int

class discord.ThreadMetadata(data: Dict)[source]#

Represents a Thread’ metadata

New in version 0.8.0.

Parameters

data (dict) – The metadata

property archive_timestamp: str#

The archived timestamp

Return type

str

property archived: bool#

If the thread is archived

Return type

bool

property auto_archive_duration: int#

The archived duration

Return type

int

property locked: bool#

If the thread is locked or not

Return type

bool

class discord.ThreadMember(data: Dict)[source]#

Represents a Discord Thread Member

New in version 0.8.0.

Parameters

data (dict) – The raw Member data

property flags: int#

Gives the thread members flags

Return type

int

property id: int#

Gives the thread id

Return type

int

property join_timestamp: str#

Gives the thread members join time

Return type

str

property user_id: int#

Gives the thread members user id

Return type

int

class discord.StageInstance(data: Dict)[source]#

Represents a Discord Stage Instance

New in version 0.8.0.

Parameters

data (dict) – The raw stage instance data

property channel_id: int#

Gives the channel id of the stage instance

Return type

int

property guild_id: int#

Gives the guild id of the stage instance

Return type

int

property id: int#

Gives the stage instance id

Return type

int

privacy_level() int[source]#

Gives the stage instance’ privacy level

Return type

int

property topic: str#

Gives the stage instance’ topic

Return type

str

Event Reference#

Guilds#

Messages#

Channels#

Interactions#

Etc#

Snowflakes#

discord.Snowflakeish#

alias of int

discord.SnowflakeishList#

alias of List[int]

discord.SnowflakeishOr#

alias of Union[discord.snowflake.T, int]

State#

class discord.Hold[source]#

A hold of cache, easily swapable with a db.

class discord.ConnectionState(**options)[source]#

The Connection State

New in version 0.4.0.

Note

The connection state is responsible for caching everything, meaning most classes will depend on it.

_bot_intents#

The cached bot intents, used for Gateway

Type

int

_session_id#

The Gateway, session id

Type

int

_voice_session_id#

The Voice Gateway Session ID

Type

int

_seq#

The Gateway seq number, can be None.

Type

int

app#

The bot app

New in version 0.5.0.

Type

Client

_said_hello#

If the Gateway got a hello or not.

Type

bool

loop :class:`asyncio.AbstractEventLoop`

The current loop

_bot_presences#

A list of the bots presences

Type

list

_bot_status#

The bot status, e.g. online

Type

str

_bot_presence_type#

The bot presence type, defaults to 0

Type

int

listeners#

The bot listeners

Type

dict

shard_count#

the number of shards.

New in version 0.6.0.

Type

int

File#

class discord.File(fp: Union[str, bytes, os.PathLike, io.BufferedIOBase], *, filename: Optional[str] = None, spoiler: bool = False)[source]#

Represents a Discord file.

New in version 0.4.0.

Parameters
  • fp – The File path, can be str, bytes, os.PathLike, os.BufferedIOBase.

  • filename – The filename, defaults None,

  • spoiler – If the file should be seeable or not.

Intents#

class discord.Intents[source]#

Helps defining your Intents. For a full list of intents and there usage please visit https://discord.dev/topics/gateway#gateway-intents

New in version 0.3.0.

ALL = 65535#

Adding this will give you every intent

ALL_DM = 28672#

Adding this will give you every dm intent

ALL_PRIVLEDGED = 36611#

Adding this will give you every priviledged intent

ALL_UNPRIVLEDGED = 28924#

Adding this will give you every un-priviledged intent

DIRECT_MESSAGES = 4096#

Adding this will allow your bot to listen to:

  • MESSAGE_CREATE

  • MESSAGE_UPDATE

  • MESSAGE_DELETE

DIRECT_MESSAGE_REACTIONS = 8192#

Adding this will allow your bot to listen to:

  • REACTION_ADD

  • REACTION_REMOVE

  • REACTION_REMOVE_ALL

  • REACTION_REMOVE_EMOJI

DIRECT_MESSAGE_TYPING = 16384#

Adding this will allow your bot to listen to:

  • TYPING

GUILDS = 1#

Adding this will allow your bot to listen to:

  • GUILD_JOIN

  • GUILD_UPDATE

  • GUILD_DELETE

  • GUILD_ROLE_CREATE

  • GUILD_ROLE_UPDATE

  • GUILD_ROLE_DELETE

  • CHANNEL_CREATE

  • CHANNEL_EDIT

  • CHANNEL_DELETE

  • CHANNEL_PINS_UPDATE

GUILD_BANS = 4#

Adding this will allow your bot to listen to:

Warning

This is a priviledged intent, and requires you to enable it to use.

  • GUILD_BAN_ADD

  • GUILD_BAN_REMOVE

GUILD_EMOJIS_AND_STICKERS = 8#

Adding this will allow your bot to listen to:

  • GUILD_EMOJIS_UPDATE

  • GUILD_STICKERS_UPDATE

GUILD_INTEGRATIONS = 16#

Adding this will allow your bot to listen to:

Note

this event(s) hasn’t been added to the core library yet

  • INTEGRATION_CREATE

  • INTEGRATION_UPDATE

  • INTEGRATION_DELETE

GUILD_INVITES = 64#

Adding this will allow your bot to listen to:

  • INVITE_CREATE

  • INVITE_DELETE

GUILD_MEMBERS = 2#

Adding this will allow your bot to listen to:

Warning

This is a priviledged intent, and requires you to enable it to use.

  • GUILD_MEMBER_ADD

  • GUILD_MEMBER_UPDATE

  • GUILD_MEMBER_REMOVE

GUILD_MESSAGES = 512#

Adding this will allow your bot to listen to:

  • MESSAGE_CREATE

  • MESSAGE_UPDATE

  • MESSAGE_DELETE

  • MESSAGE_BULK_DELETE

GUILD_MESSAGE_REACTIONS = 1024#

Adding this will allow your bot to listen to:

  • REACTION_ADD

  • REACTION_REMOVE

  • REACTION_REMOVE_ALL

  • REACTION_REMOVE_EMOJI

GUILD_MESSAGE_TYPING = 2048#

Adding this will allow your bot to listen to:

  • TYPING

GUILD_PRESENCES = 256#

Adding this will allow your bot to listen to:

Warning

This is a priviledged intent, and requires you to enable it to use.

  • PRESENCE_UPDATE

GUILD_SCHEDULED_EVENTS = 65536#

Adding this will allow your bot to listen to:

  • SCHEDULED_EVENT (SCHEDULED_EVENT_CREATE)

  • SCHEDULED_EVENT_EDIT (SCHEDULED_EVENT_UPDATE)

  • SCHEDULED_EVENT_DELETE

  • SCHEDULED_EVENT_JOIN

  • SCHEDULED_EVENT_LEAVE

GUILD_VOICE_STATES = 128#

Adding this will allow your bot to listen to:

  • RAW_VOICE_STATE_UPDATE

GUILD_WEBHOOKS = 32#

Adding this will allow your bot to listen to:

  • WEBHOOKS_UPDATE

MESSAGE_CONTENT = 32768#

Adding this will allow your bot to receive content within MESSAGE events which aren’t in direct messages.

PRIVLEDGED_GUILD = 3843#

Adding this will give you every priviledged and non-privledged guild intent

UNPRIVLEDGED_GUILD = 252#

Adding this will give you every non-privledged guild intent

Embed#

class discord.Embed(title: Optional[str] = None, description: Optional[str] = None, url: Optional[str] = None, date: Optional[str] = None, color: Optional[Union[int, discord.color.Color]] = None, colour: Optional[Union[int, discord.colour.Colour]] = None, timestamp: Optional[datetime.datetime] = None)[source]#

Represents a Discord Embed.

Parameters
  • title – The embed title

  • description – The embed description

  • url – The embed url

  • date – The embed date

  • color – The embed color

  • colour – The embed colour

  • timestamp – The embed timestamp

add_field(name: str, value: str, inline: bool = True)[source]#

Adds a field to the embed

Parameters
  • name – The field name

  • value – The field value

  • inline – If the field should be inline

remove_author()[source]#

Removes the author from the embed

remove_field(name: str)[source]#

Removes the field

Parameters

name – The field to remove

Removes the footer

set_author(name: str, url: Optional[str] = None, icon_url: Optional[str] = None)[source]#

Sets the embed author

Parameters
  • name – The author name

  • url – The author’s url

  • icon_url – The author’s icon_url

Sets the footer

Parameters
  • text – A text footer

  • icon_url – The icon url of the footer

set_thumbnail(url: Optional[str] = None)[source]#

Sets a thumbnail on the embed

Parameters

url – The thumbnail url

to_dict()[source]#

Gives the dictionary which the embed is within

Returns

The dict

Return type

obj dict

Interaction#

class discord.Interaction(data: Dict, state)[source]#

Represents a Discord Interaction & Interaction Response

Parameters
  • data – The interaction data

  • state – The connection state

webhook#

A Webhook

token#

The interaction token

type#

The interaction type

guild_id#

The interaction guild id

channel_id#

The interaction channel id

data#

The interaction data

id#

The interaction id

message#

The interaction message

Note

This only appears on Component interactions.

defer(invisable: bool = False)[source]#

defers an interaction response

Return type

An empty Interaction.respond()

followup(content: Optional[str] = None, tts: bool = False, embed: Optional[discord.embed.Embed] = None, embeds: Optional[List[discord.embed.Embed]] = None)[source]#

Followup a defered interaction.

Parameters
  • content – The message content

  • tts – Text-To-Speach

  • embed – A Embed object or dict

  • embeds – A list of Embed or dict

  • allowed_mentions – A allowed mentions object

Return type

Webhook.execute()

property member#

Returns the member object of the invoker.

Return type

Member

respond(content: Optional[str] = None, modal: Optional[Dict[str, Any]] = None, tts: bool = False, embed: Optional[discord.embed.Embed] = None, embeds: Optional[List[discord.embed.Embed]] = None, allowed_mentions: Optional[discord.types.allowed_mentions.MentionObject] = None, type: Optional[int] = 4, invisable: Optional[bool] = False)[source]#

Send a response to a interaction

Parameters
  • content – The message content

  • tts – Text-To-Speach

  • embed – A Embed object or dict

  • embeds – A list of Embed or dict

  • allowed_mentions – A allowed mentions object

  • type – The interaction type

  • invisable – If the interaction should only be seeable by the invoker.

send(content: Optional[str] = None, **kwargs)[source]#

Shorthand for Interaction.respond()

New in version 1.0.

Exceptions#

exception discord.DiscordError[source]#

The base exception class for discord.io

exception discord.RESTError[source]#

REST Errors

exception discord.Forbidden[source]#

Forbidden from a URL

exception discord.NotFound[source]#

Endpoint Not Found

exception discord.ServerError[source]#

A Discord Server Error

Exception Hierarcy#