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 forreleaselevel
are ‘alpha’, ‘beta’, ‘candidate’ and ‘final’.
REST API#
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
state – The
ConnectionState
cache to use.dispatcher – The
Dispatcher
to use.shard_id (
int
) – The shard number.url (
str
) – The URL to use.
: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.
- 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
state – The
ConnectionState
to use.dispatcher – The
Dispatcher
to use.factory – The
RESTFactory
to use.mobile – If your bot should have a mobile presence or not.
- class discord.VoiceGateway(state: discord.state.ConnectionState, guild_id: int, hook)[source]#
Opus#
Voice#
- class discord.VoiceClient(state: discord.state.ConnectionState, channel: discord.channels.VoiceChannel)[source]#
Used to interact with the discord voice api
- Parameters
state – The
ConnectionState
dispatcher – The
Dispatcher
gateway – The
Gateway
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
- 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.
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
- 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
- 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 namecallback – The slash command callback
options (
List
) – A list of slash command optionsguild_ids (List[
int
]) – A list of guild idsdescription (
str
) – The application command descriptiondefault_permission (
bool
) – If this slash command should have default permissions
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
- 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
- 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
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 from_hex(hex_code: str)[source]#
A factory color method which gets its color from a hex code string
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
- property channel#
Returns the channel which this message took place in.
- Return type
- 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
- 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
- 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
- class discord.User(usr: dict)[source]#
Represents a Discord User
New in version 0.6.0.
- Parameters
usr – The user in dict format
- 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
- 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 nicknameroles (Optional[
list`[:class:`int
]]) – Chaneg the members rolesmute (Optional[
bool
]) – If the member should be muteddeaf (Optional[
bool
]) – If the member should be deafendchannel_id (Optional[
int
]) – The channel id to move the member totimeout (Optional[
str
]) – Set a timeout for the member, has to be a ISO8601 timestanpreason (Optional[
str
]) – A reason why you are editing this member
- Returns
None
- kick(reason: Optional[str] = None)[source]#
Kicks the member
- Parameters
reason (Optional[
str
]) – A reason why you are kicking this member
Gives a timestamp of when the member started boosting
- Returns
None
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?
- 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_channels()[source]#
Gives a list of Channel objects
- Return type
List[Union[
TextChannel
,VoiceChannel
,Category
,DMChannel
,GroupDMChannel
,Thread
]]
- class discord.Role(data: Dict, factory)[source]#
Represents a Discord Role
New in version 0.8.0.
- Parameters
data (
dict
) – The raw role data
- 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
None
- property creator: discord.user.User#
Gives a
User
of the creator of this scheduled event- Return type
- image(format: discord.enums.FormatType = '.png')[source]#
Gives the url of the scheduled event’ banner
- Return type
- property metadata: discord.guild.ScheduledEventMetadata#
Gives the scheduled event metadata
- Return type
- 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
- 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
]
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.
- class discord.Sticker(data: dict, state: discord.state.ConnectionState)[source]#
Represents a Discord Sticker.
New in version 0.8.0.
- Parameters
data (
dict
) – The raw Sticker datastate (
ConnectionState
) – The connection state
- from_dict#
The raw Sticker data
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 datastate (
state
) – The connection state
- class discord.TextChannel(data: Dict, state: discord.state.ConnectionState)[source]#
Represents a Discord Text Channel
- Parameters
data (
dict
) – The raw json datastate (
ConnectionState
) – The connection state
- class discord.VoiceChannel(data: Dict, state: discord.state.ConnectionState)[source]#
Represents a Discord Voice Channel
New in version 0.8.0.
- Parameters
data (
dict
) – The raw channel datastate (
ConnectionState
) – The connection state
- class discord.DMChannel(data: Dict, state: discord.state.ConnectionState)[source]#
Represents a Discord DM Channel
New in version 0.8.0.
- Parameters
data (
dict
) – The raw datastate (
ConnectionState
) – The connection state
- 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
- owner() discord.user.User [source]#
Returns the User which is the owner of this Group DM
- Return type
- class discord.Thread(data: Dict, state: discord.state.ConnectionState)[source]#
Represents a Discord Thread
New in version 0.8.0.
- Parameters
data (
dict
) – The raw thread datastate (
ConnectionState
) – The connection state
- property metadata: discord.channels.ThreadMetadata#
Gives the thread’ metadata
- Return type
- class discord.ThreadMetadata(data: Dict)[source]#
Represents a Thread’ metadata
New in version 0.8.0.
- Parameters
data (
dict
) – The metadata
- class discord.ThreadMember(data: Dict)[source]#
Represents a Discord Thread Member
New in version 0.8.0.
- Parameters
data (
dict
) – The raw Member data
Event Reference#
Guilds#
Messages#
Channels#
Interactions#
Etc#
Snowflakes#
State#
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
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
Interaction#
- class discord.Interaction(data: Dict, state)[source]#
Represents a Discord Interaction & Interaction Response
- Parameters
data – The interaction data
state – The connection state
- 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.
- 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
- send(content: Optional[str] = None, **kwargs)[source]#
Shorthand for
Interaction.respond()
New in version 1.0.