Welcome to discord.aio’s documentation!

See the reference documentation.

discord.aio

PyPI version Python version Module status License Discord Documentation Status
discord.aio is an asynchronous Discord API wrapper

Currently under very early development

Python 3.6+ only.

Documentation

You can find the module documentation here: documentation

Installation

With pip:

  • pip3 install discord.aio

From source:

  • git clone https://github.com/Ryozuki/discord.aio && cd discord.aio && pip3 install .

Local development

  • git clone https://github.com/Ryozuki/discord.aio
  • cd discord.aio && pip3 install -e .

Example bot

import asyncio
import os
import logging
from discordaio import DiscordBot

logging.basicConfig(
    level='DEBUG', format='%(asctime)s - %(name)s - %(levelname)s: %(message)s')
logger = logging.getLogger('my_lovely_bot')

if __name__ == '__main__':
    TOKEN = os.environ['DISCORD_TOKEN']

    bot = DiscordBot(TOKEN)

    @bot.event()
    async def on_ready():
        logger.info('Connected!')
        logger.info(f'My username is {bot.user}')

    @bot.event('on_message') # You can also use a custom function name.
    async def foo_bar(message):
        logger.info(f'{message.author}: {message.content}')

Here you can find a more extensive example.

TODO

Your first bot

TODO: Do this

Events

Events

Event: on_ready

Raised when:

  • The client is ready and connected.

Note: Before this event is raised, DiscordBot.user is filled with information.

@bot.event()
async def on_ready():
    print('Connected!')
    print(f'My username is {bot.user}')
Event: on_resumed

Raised when:

  • A client has sent a resume payload to the gateway (for resuming existing sessions).
Event: on_invalid_session

Raised when:

  • The gateway could not initialize a session after receiving an Opcode 2 Identify
  • The gateway could not resume a previous session after receiving an Opcode 6 Resume
  • The gateway has invalidated an active session and is requesting client action

Event Parameters:

  • resume (bool): Indicates whether the client can resume.
Event: on_channel_create

Raised when:

  • A new channel is created

Event Parameters:

  • channel (Channel): The created channel
Event: on_channel_update

Raised when:

  • A channel is updated

Event Parameters:

  • channel (Channel): The updated channel
Event: on_channel_delete

Raised when:

  • A channel is deleted

Event Parameters:

  • channel (Channel): The deleted channel
Event: on_channel_pin

Raised when:

  • A message is pinned or unpinned in a text channel.

Note: This is not raised when a pinned message is deleted.

Event Parameters:

  • channel_id (int): The id of the channel
  • last_pin_timestamp (int): The time at which the most recent pinned message was pinned
Event: on_guild_create

Raised when:

  • After the on_ready event, to fullfill the guild information.
  • When a Guild becomes available again to the client.
  • When the current user joins a new Guild.

Event Parameters:

  • guild (Guild): The guild
@bot.event()
async def on_guild_create(guild):
    print(f'I\'m connected to {guild.name} guild, it got {len(guild.channels)} channels.')
Event: on_guild_delete

Raised when:

  • A guild becomes unavailable during a guild outage
  • The user leaves or is removed from a guild
  • When the current user joins a new Guild.

Note: If the unavailable attribute is not set, the user was removed from the guild.

Event Parameters:

  • guild (Guild): The guild
@bot.event()
async def on_guild_delete(guild):
    print(f'{guild.name} went offline?')
    if not guild.unavailable:
        print(f'I got removed from {guild}!')
Event: on_guild_emojis_update

Raised when:

  • When a guild’s emojis have been updated.

Event Parameters:

  • guild_id (int): The guild id
  • emojis (list): A list of emojis
Event: on_guild_integrations_update

Raised when:

  • When a guild integration is updated.

Event Parameters:

  • guild_id (int): The guild id.
Event: on_guild_member_add

Raised when:

  • When a new user joins a guild.

Event Parameters:

  • guild_id (int): The guild id.
  • member (GuildMember): The user that joined.
Event: on_guild_member_remove

Raised when:

  • A user is removed from a guild (leave/kick/ban).

Event Parameters:

  • guild_id (int): The guild id.
  • user (User): The user that was removed/left.
Event: on_guild_member_update

Raised when:

  • A guild member is updated

Event Parameters:

  • guild_id (int): The guild id.
  • roles (list): User role ids.
  • user (User): The user.
  • nick (str): Nickname of the user in the guild.
Event: on_guild_members_chunk

Raised when:

  • In response to Guild Request Members.

Event Parameters:

  • guild_id (int): The guild id.
  • members (list): Set of guild members
Event: on_guild_role_create

Raised when:

  • A guild role is created.

Event Parameters:

  • guild_id (int): The guild id.
  • role (Role): The role created
Event: on_guild_role_update

Raised when:

  • A guild role is updated.

Event Parameters:

  • guild_id (int): The guild id.
  • role (Role): The role updated
Event: on_guild_role_delete

Raised when:

  • A guild role is deleted.

Event Parameters:

  • guild_id (int): The guild id.
  • role_id (int): The id of the deleted role
Event: on_ban

Raised when:

  • A user is banned from a guild

Event Parameters:

  • guild_id (int): The guild id.
  • user (User): The banned .
Event: on_ban_remove

Raised when:

  • A user is unbanned from a guild

Event Parameters:

  • guild_id (int): The guild id.
  • user (User): The unbanned user.
Event: on_message

Raised when:

  • A user send a message to a channel

Event Parameters:

  • user_id (int): The id of the user that started typing.
  • channel_id (int): The id of the channel where the action happened.
  • timestamp (int): The timestamp telling when it happened.
@bot.event()
async def on_message(message):
    print(f'{message.author}: {message.content}')
Event: on_message_update

Raised when:

  • A message is updated.

Note: Unlike creates, message updates may contain only a subset of the full message object payload (but will always contain an id and channel_id)

Event Parameters:

  • message (ChannelMessage): The Channel message that has been updated
@bot.event()
async def on_message_create(message):
    print(f'A message with id {message.id} has been updated.')
Event: on_message_delete

Raised when:

  • A message is deleted.

Event Parameters:

  • id (int): The id of the message.
  • channel_id (int): The id of the channel.
@bot.event()
async def on_message_delete(id, channel_id):
    print(f'A message with id {id} has been deleted.')
Event: on_message_delete_bulk

Raised when:

  • Multiple messages are deleted at once.

Event Parameters:

  • ids (int): The ids of the messages
  • channel_id (int): The id of the channel
@bot.event()
async def on_message_delete_bulk(ids, channel_id):
    print(f'Multiple messages have been deleted')
Event: on_message_reaction_add

Raised when:

  • A user adds a reaction to a message

Event Parameters:

  • user_id (int): The id of the user
  • channel_id (int): The id of the channel
  • message_id (int): The id of the message
  • emoji (Emoji): The emoji used to react
@bot.event()
async def on_message_reaction_add(user_id, channel_id, message_id, emoji):
    user = await bot.get_user(user_id)
    print(f'{user} reacted to a message with {emoji.name}')
Event: on_message_reaction_remove

Raised when:

  • A user removes a reaction from a message

Event Parameters:

  • user_id (int): The id of the user
  • channel_id (int): The id of the channel
  • message_id (int): The id of the message
  • emoji (Emoji): The emoji used to react
@bot.event()
async def on_message_reaction_add(user_id, channel_id, message_id, emoji):
    user = await bot.get_user(user_id)
    print(f'{user} removed reaction {emoji.name} from a message.')
Event: on_message_reaction_remove_all

Raised when:

  • A user explicitly removes all reactions from a message.

Event Parameters:

  • channel_id (int): The id of the channel
  • message_id (int): The id of the message
Event: on_presence_update

Raised when:

  • A user’s presence is updated for a guild.

Note: The user object within this event can be partial, the only field which must be set is the id field

Event Parameters:

  • user (User): The user presence is being updated for
  • roles (list): Ids of the roles this user is in
  • game (?Activity): Null, or the user’s current activity
  • guild_id (int): The guild id
  • status (str): Either “idle”, “dnd”, “online”, or “offline”
Event: on_typing_start

Raised when:

  • A user starts typing in a channel

Event Parameters:

  • user_id (int): The id of the user that started typing.
  • channel_id (int): The id of the channel where the action happened.
  • timestamp (int): The timestamp telling when it happened.
@bot.event()
async def on_typing_start(user_id, channel_id, timestamp):
    user = await bot.get_user(user_id)
    print(f'{user} started typing!')
Event: on_user_update

Raised when:

  • Properties about the user change

Event Parameters:

  • user (User): The user that has been updated
Event: on_voice_state_update

Raised when:

  • Someone joins/leaves/moves voice channels.

Event Parameters:

  • voice_state (VoiceState): The voice state object
Event: on_voice_server_update

Raised when:

  • A guild’s voice server is updated.
  • This is sent when initially connecting to voice, and when the current voice instance fails over to a new server.

Event Parameters:

  • token (str): Voice connection token-
  • guild_id (int): The guild this voice server update is for
  • endpoint (str): The voice server host
Event: on_webhooks_update

Raised when:

  • A guild’s voice server is updated.
  • This is sent when initially connecting to voice, and when the current voice instance fails over to a new server.

Event Parameters:

  • guild_id (int): Id of the guild
  • channel_id (int): Id of the channel

discordaio

discord.aio is an asynchronous Discord API wrapper for python 3.6+

Submodules

discordaio.activity
Classes
class discordaio.activity.Activity(name='', type=0, url='', timestamps=None, application_id=0, details='', state='', party=None, assets=None)[source]

Represents a discord activity

New in version 0.2.0.

name

str – the activity’s name

type

int – activity type

url

str, optional – stream url, is validated when type is 1

timestamps

Timestamps – object unix timestamps for start and/or end of the game

application_id

int, optional – application id for the game

details

str, optional – what the player is currently doing

state

str, optional – the user’s current party status

party

Party – object information for the current party of the player

assets

Assets – object images for the presence and their hover texts

Inheritance

Inheritance diagram of Activity
class discordaio.activity.ActivityParty(id='', size=[])[source]

Activity party

New in version 0.2.0.

id

str, optional – the id of the party

size

list of int – array of two integers (current_size, max_size), used to show the party’s current and maximum size

Inheritance

Inheritance diagram of ActivityParty
class discordaio.activity.ActivityTimestamps(start=0, end=0)[source]

Activity timestamps

New in version 0.2.0.

start

int, optional – unix time (in milliseconds) of when the activity started

end

int, optional – unix time (in milliseconds) of when the activity ends

Inheritance

Inheritance diagram of ActivityTimestamps
class discordaio.activity.ActivityAssets(large_image='', large_text='', small_image='', small_text='')[source]

Activity assets

New in version 0.2.0.

large_image

str, optional – the id for a large asset of the activity, usually a snowflake

large_text

str, optional – text displayed when hovering over the large image of the activity

small_image

str, optional – the id for a small asset of the activity, usually a snowflake

small_text

str, optional – text displayed when hovering over the small image of the activity

Inheritance

Inheritance diagram of ActivityAssets
discordaio.base
Classes
class discordaio.base.DiscordObject[source]

Base class for discord objects.

Inheritance

Inheritance diagram of DiscordObject
classmethod await from_api_res(coro_or_json_or_str)[source]

Parses a discord API response

discordaio.channel

Contains all related Channel Discord objects

Classes
class discordaio.channel.Channel(id=0, type=0, guild_id=0, position=0, permission_overwrites=[], name='', topic='', nsfw=False, last_message_id=0, bitrate=0, user_limit=0, recipients=[], icon='', owner_id=0, application_id=0, parent_id=0, last_pin_timestamp=None)[source]

Represents a guild or DM channel within Discord.

New in version 0.2.0.

id

int – the id of this channel

value_type

int – the value_type of channel

guild_id

int, optional – the id of the guild

position

int, optional – sorting position of the channel

permission_overwrites

list of Overwrite, optional – explicit permission overwrites for members and roles

name

str, optional – the name of the channel (2-100 characters)

topic

str, optional – the channel topic (0-1024 characters)

nsfw

bool, optional – if the channel is nsfw

last_message_id

int, optional – the id of the last message sent in this channel (may not point to an existing or valid message)

bitrate

int, optional – the bitrate (in bits) of the voice channel

user_limit

int, optional – the user limit of the voice channel

recipients

list of User, optional – the recipients of the DM

icon

str, optional – icon hash

owner_id

int, optional – id of the DM creator

application_id

int, optional – application id of the group DM creator if it is bot-created

parent_id

int, optional – id of the parent category for a channel

last_pin_timestamp

int, optional – timestamp when the last pinned message was pinned

Inheritance

Inheritance diagram of Channel
class discordaio.channel.ChannelMessage(id=0, channel_id=0, author=None, content='', timestamp=None, edited_timestamp=None, tts=False, mention_everyone=False, mentions=[], mention_roles=[], attachments=[], embeds=[], reactions=[], nonce=0, pinned=False, webhook_id=0, type=0, activity=<discordaio.channel.MessageActivity object>, application=<discordaio.channel.MessageApplication object>)[source]

Represents a message sent in a channel within Discord.

New in version 0.2.0.

Note

The author object follows the structure of the User object, but is only a valid user in the case where the message is generated by a user or bot user. If the message is generated by a Webhook, the author object corresponds to the webhook’s id, username, and avatar. You can tell if a message is generated by a webhook by checking for the webhook_id on the message object.

id

int – id of the message

channel_id

int – id of the channel the message was sent in

author

user – object the author of this message (not guaranteed to be a valid user, see below)

content

str – contents of the message

timestamp

int – timestamp when this message was sent

edited_timestamp

int – timestamp when this message was edited (or null if never)

tts

bool – whether this was a TTS message

mention_everyone

bool – whether this message mentions everyone

mentions

list of User – objects users specifically mentioned in the message

mention_roles

list of Role – object ids roles specifically mentioned in this message

attachments

list of Attachment – objects any attached files

embeds

list of Embed – objects any embedded content

reactions

list of Reaction – objects reactions to the message

nonce

int, optional – used for validating a message was sent

pinned

bool – whether this message is pinned

webhook_id

int, optional – if the message is generated by a webhook, this is the webhook’s id

type

int – type of message

activity

MessageActivity – activity object sent with Rich Presence-related chat embeds

application

MessageApplication – application object sent with Rich Presence-related chat embeds

Inheritance

Inheritance diagram of ChannelMessage
class discordaio.channel.Overwrite(id=0, type='', allow=0, deny=0)[source]

Represents a Overwrite object.

New in version 0.2.0.

id

int – role or user id

type

str – either “role” or “member”

allow

int – permission bit set

deny

int – permission bit set

Inheritance

Inheritance diagram of Overwrite
class discordaio.channel.MessageActivity(type=None, party_id='')[source]

Represents a Message Activity.

New in version 0.2.0.

type

int – type of message activity

party_id

str, optional – party_id from a Rich Presence event

Inheritance

Inheritance diagram of MessageActivity
class discordaio.channel.MessageApplication(id=0, cover_image='', description='', icon='', name='')[source]

Represents a Message Application.

New in version 0.2.0.

id

int – id of the application

cover_image

str – id of the embed’s image asset

description

str – application’s description

icon

str – id of the application’s icon

name

str – name of the application

Inheritance

Inheritance diagram of MessageApplication
class discordaio.channel.Reaction(count=0, me=False, emoji=None)[source]

Represents a Reaction.

New in version 0.2.0.

count

int – times this emoji has been used to react

me

bool – whether the current user reacted using this emoji

emoji

Emoji – emoji information

Inheritance

Inheritance diagram of Reaction
class discordaio.channel.Embed(title='', type='', description='', url='', timestamp=None, color=0, footer=<discordaio.channel.EmbedFooter object>, image=<discordaio.channel.EmbedImage object>, thumbnail=<discordaio.channel.EmbedThumbnail object>, video=<discordaio.channel.EmbedVideo object>, provider=<discordaio.channel.EmbedProvider object>, author=<discordaio.channel.EmbedAuthor object>, fields=[])[source]

Represents a discord Embed

New in version 0.2.0.

title

str – title of embed

type

str – type of embed (always “rich” for webhook embeds)

description

str – description of embed

url

str – url of embed

timestamp

int – timestamp of embed content

color

int – color code of the embed

footer

EmbedFooter – footer information

image

EmbedImage – image information

thumbnail

EmbedThumbnail – thumbnail information

video

EmbedVideo – video information

provider

EmbedProvider – provider information

author

EmbedAuthor – author information

fields

list of EmbedField – fields information

Inheritance

Inheritance diagram of Embed
class discordaio.channel.EmbedThumbnail(url='', proxy_url='', height=0, width=0)[source]

Represents a embed thumbnail object

New in version 0.2.0.

url

str – source url of thumbnail (only supports http(s) and attachments)

proxy_url

str – a proxied url of the thumbnail

height

int – height of thumbnail

width

int – width of thumbnail

Inheritance

Inheritance diagram of EmbedThumbnail
class discordaio.channel.EmbedVideo(url='', height=0, width=0)[source]

Represents a embed video

New in version 0.2.0.

url

str – source url of video

height

int – height of video

width

int – width of video

Inheritance

Inheritance diagram of EmbedVideo
class discordaio.channel.EmbedImage(url='', proxy_url='', height=0, width=0)[source]

Represents a embed image

New in version 0.2.0.

url

str – source url of image (only supports http(s) and attachments)

proxy_url

str – a proxied url of the image

height

int – height of image

width

int – width of image

Inheritance

Inheritance diagram of EmbedImage
class discordaio.channel.EmbedProvider(name='', url='')[source]

Represents a embed provider

New in version 0.2.0.

name

str – name of provider

url

str – url of provider

Inheritance

Inheritance diagram of EmbedProvider
class discordaio.channel.EmbedAuthor(name='', url='', icon_url='', proxy_icon_url='')[source]

Represents a embed author

New in version 0.2.0.

name

str – name of author

url

str – url of author

icon_url

str – url of author icon (only supports http(s) and attachments)

proxy_icon_url

str – a proxied url of author icon

Inheritance

Inheritance diagram of EmbedAuthor
class discordaio.channel.EmbedFooter(text='', icon_url='', proxy_icon_url='')[source]

Represents a embed footer

New in version 0.2.0.

text

str – footer text

icon_url

str – url of footer icon (only supports http(s) and attachments)

proxy_icon_url

str – a proxied url of footer icon

Inheritance

Inheritance diagram of EmbedFooter
class discordaio.channel.EmbedField(name='', value='', inline=False)[source]

Represents a embed field

New in version 0.2.0.

name

str – name of the field

value

str – value of the field

inline

bool – whether or not this field should display inline

Inheritance

Inheritance diagram of EmbedField
class discordaio.channel.Attachment(id=0, filename='', size=0, url='', proxy_url='', height=0, width=0)[source]

Represents a attachment

New in version 0.2.0.

id

int – attachment id

filename

str – name of file attached

size

int – size of file in bytes

url

str – source url of file

proxy_url

str – a proxied url of file

height

int – height of file (if image)

width

int – width of file (if image)

Inheritance

Inheritance diagram of Attachment
discordaio.client
Classes
  • DiscordBot: This class represents a discord bot object, it has many utility methods for making a bot.
class discordaio.client.DiscordBot(token: str)[source]

This class represents a discord bot object, it has many utility methods for making a bot.

New in version 0.2.0.

token

str – The discord token used for authentication

http

HTTPHandler – Used for making http requests and websocket creation.

guilds

list of Guild – The list of guilds the bot is in.

user

User – The user object of the bot.

ws

DiscordWebsocket – The websocket used for communication

Inheritance

Inheritance diagram of DiscordBot
await delete_channel(channel_id: int) → discordaio.channel.Channel[source]

Deletes a channel.

Note

Delete a channel, or close a private message. Requires the ‘MANAGE_CHANNELS’ permission for the guild. Deleting a category does not delete its child channels; they will have their parent_id removed and a Channel Update Gateway event will fire for each of them. Returns a channel object on success. Fires a Channel Delete Gateway event.

New in version 0.2.0.

Parameters:channel_id (int) – The channel id
Returns:The deleted channel
Return type:Channel
event(name: str = None)[source]

DiscordBot event decorator, uses the function’s name or the ‘name’ parameter to subscribe to a event

New in version 0.2.0.

await exit()[source]

Disconnects the bot

New in version 0.2.0.

await get_channel(channel_id: int) → discordaio.channel.Channel[source]

Gets a channel from it’s id

New in version 0.2.0.

Parameters:channel_id (int) – The channel id
Returns:The channel
Return type:Channel
await get_dms() → list[source]

Gets a list of dms.

New in version 0.2.0.

Returns:The DMs channels
Return type:list of Channel
await get_guild(guild_id: int) → discordaio.guild.Guild[source]

Returns a Guild object from a guild id.

New in version 0.2.0.

Parameters:guild_id (int) – The guild id
Returns:The requested guild
Return type:Guild
await get_guild_member(guild: discordaio.guild.Guild, member_id: int) → discordaio.guild.GuildMember[source]

Gets a guild member info for the guild and the member id.

New in version 0.2.0.

Parameters:
  • guild (Guild) – The guild
  • member_id (int) – The member id
Returns:

The guild member

Return type:

GuildMember

await get_guild_members(guild: discordaio.guild.Guild)[source]

Gets and fills the guild with the members info.

New in version 0.2.0.

Parameters:guild (Guild) – The guild to fill the members.
await get_guilds() → list[source]

Returns a list of guilds where the bot is in.

New in version 0.2.0.

await get_self_user() → discordaio.user.User[source]

Returns the bot user object. (it’s like get_user(‘@me’))

New in version 0.2.0.

await get_user(id: int) → discordaio.user.User[source]

Gets the user object from the given user id.

New in version 0.2.0.

Parameters:id (int) – The user id
Returns:The requested user
Return type:User
await leave_guild(guild_id: int)[source]

Leaves a guild.

New in version 0.2.0.

Parameters:guild_id (int) – The guild id
run() → None[source]

Starts the bot, making it connect to discord.

New in version 0.2.0.

discordaio.constants
Variables
discordaio.constants.DISCORD_CDN

str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’. .. code-block:: guess

discordaio.constants.DISCORD_API_URL

str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’. .. code-block:: guess

discordaio.emoji
Classes
  • Emoji: Represents a emoji object
class discordaio.emoji.Emoji(id=0, name='', roles=[], user=None, require_colons=False, managed=False, animated=False)[source]

Represents a emoji object

New in version 0.2.0.

id

int – emoji id

name

str – emoji name

roles

list of Role – object ids roles this emoji is whitelisted to

user

User – object user that created this emoji

require_colons

bool, optional – whether this emoji must be wrapped in colons

managed

bool, optional – whether this emoji is managed

animated

bool, optional – whether this emoji is animated

Inheritance

Inheritance diagram of Emoji
discordaio.enums
Classes
class discordaio.enums.MessageNotificationLevel[source]

An enumeration.

Inheritance

Inheritance diagram of MessageNotificationLevel
class discordaio.enums.ExplicitContentFilterLevel[source]

An enumeration.

Inheritance

Inheritance diagram of ExplicitContentFilterLevel
class discordaio.enums.MFALevel[source]

An enumeration.

Inheritance

Inheritance diagram of MFALevel
class discordaio.enums.VerificationLevel[source]

An enumeration.

Inheritance

Inheritance diagram of VerificationLevel
class discordaio.enums.ChannelTypes[source]

An enumeration.

Inheritance

Inheritance diagram of ChannelTypes
class discordaio.enums.MessageActivityTypes[source]

An enumeration.

Inheritance

Inheritance diagram of MessageActivityTypes
class discordaio.enums.GatewayOpcodes[source]

An enumeration.

Inheritance

Inheritance diagram of GatewayOpcodes
discordaio.exceptions
Exceptions
exception discordaio.exceptions.WebSocketCreationError[source]

Inheritance

Inheritance diagram of WebSocketCreationError
exception discordaio.exceptions.EventTypeError[source]

Inheritance

Inheritance diagram of EventTypeError
exception discordaio.exceptions.AuthorizationError[source]

Inheritance

Inheritance diagram of AuthorizationError
discordaio.guild
Classes
class discordaio.guild.Guild(id=0, name='', icon='', splash='', owner=False, owner_id=0, permissions=0, region='', afk_channel_id=0, afk_timeout=0, embed_enabled=False, embed_channel_id=0, verification_level=0, default_message_notifications=0, explicit_content_filter=0, roles=[], emojis=[], features=[], mfa_level=0, application_id=0, widget_enabled=False, widget_channel_id=0, system_channel_id=0, joined_at=None, large=None, unavailable=None, member_count=None, voice_states=None, members=[], channels=None, presences=None)[source]

Represents a guild

New in version 0.2.0.

Note

Guilds in Discord represent an isolated collection of users and channels, and are often referred to as “servers” in the UI.

id

int – guild id

name

str – guild name (2-100 characters)

icon

str – icon hash

splash

str – splash hash

owner

bool, optional – whether or not the user is the owner of the guild

owner_id

int – id of owner

permissions

int, optional – total permissions for the user in the guild (does not include channel overrides)

region

str – voice region id for the guild

afk_channel_id

int – id of afk channel

afk_timeout

int – afk timeout in seconds

embed_enabled

bool, optional – is this guild embeddable (e.g. widget)

embed_channel_id

int, optional – id of embedded channel

verification_level

int – verification level required for the guild

default_message_notifications

int – default message notifications level

explicit_content_filter

int – explicit content filter level

roles

list of Role – roles in the guild

emojis

list of Emoji – custom guild emojis

features

list of Strings – enabled guild features

mfa_level

int – required MFA level for the guild

application_id

int – application id of the guild creator if it is bot-created

widget_enabled

bool, optional – whether or not the server widget is enabled

widget_channel_id

int, optional – the channel id for the server widget

system_channel_id

int – the id of the channel to which system messages are sent

joined_at

int, optional – timestamp when this guild was joined at

large

bool, optional – whether this is considered a large guild

unavailable

bool, optional – is this guild unavailable

member_count

int, optional – total number of members in this guild

voice_states

list of Partial – (without the guild_id key)

members

list of Guild – users in the guild

channels

list of Channel – channels in the guild

presences

list of Partial – presences of the users in the guild

Inheritance

Inheritance diagram of Guild
get_icon() → str[source]

Returns the guild icon

New in version 0.2.0.

Returns:The icon link
Return type:str
get_splash()[source]

Returns the guild splash

New in version 0.2.0.

Returns:The splash link
Return type:str
is_owner(member: discordaio.guild.GuildMember) → bool[source]

Returns wether the guild member is the owner of the guild

New in version 0.2.0.

Parameters:member (GuildMember) – The member
Returns:True if it’s the owner, False otherwise.
Return type:bool
class discordaio.guild.GuildMember(user=<User Object: #, 0>, nick='', roles=[], joined_at=None, deaf=False, mute=False)[source]

Represents a guild member

New in version 0.2.0.

user

User – user object

nick

str, optional – this users guild nickname (if one is set)

roles

list of int – array of role object ids

joined_at

int – timestamp when the user joined the guild

deaf

bool – if the user is deafened

mute

bool – if the user is muted

Inheritance

Inheritance diagram of GuildMember
class discordaio.guild.GuildEmbed(enabled=False, channel_id=0)[source]

Represents a guild embed

New in version 0.2.0.

enabled

bool – if the embed is enabled

channel_id

int – the embed channel id

Inheritance

Inheritance diagram of GuildEmbed
class discordaio.guild.IntegrationAccount(id='', name='')[source]

Represents a integration account

New in version 0.2.0.

id

str – id of the account

name

str – name of the account

Inheritance

Inheritance diagram of IntegrationAccount
class discordaio.guild.Integration(id=0, name='', type='', enabled=False, syncing=False, role_id=0, expire_behavior=0, expire_grace_period=0, user=None, account=None, synced_at=None)[source]

Represents a integration

New in version 0.2.0.

id

int – integration id

name

str – integration name

type

str – integration type (twitch, youtube, etc)

enabled

bool – is this integration enabled

syncing

bool – is this integration syncing

role_id

int – id that this integration uses for “subscribers”

expire_behavior

int – the behavior of expiring subscribers

expire_grace_period

int – the grace period before expiring subscribers

user

User – object user for this integration

account

Account – account information

synced_at

int – timestamp when this integration was last synced

Inheritance

Inheritance diagram of Integration
class discordaio.guild.Ban(reason='', user=None)[source]

Represents a ban

New in version 0.2.0.

reason

str – the reason for the ban

user

User – the banned user

Inheritance

Inheritance diagram of Ban
discordaio.http
Classes
class discordaio.http.HTTPHandler(token, discord_client)[source]

Inheritance

Inheritance diagram of HTTPHandler
class discordaio.http.RateLimit(message='', retry_after=0, _global=False)[source]

Inheritance

Inheritance diagram of RateLimit
discordaio.invite
Classes
  • Invite: Represents a code that when used, adds a user to a guild.
  • InviteMetadata: Represents the invite metadata
class discordaio.invite.Invite(code='', guild=None, channel=None)[source]

Represents a code that when used, adds a user to a guild.

New in version 0.2.0.

code

str – the invite code (unique ID)

guild

Guild – the guild this invite is for

channel

Channel – the channel this invite is for

Inheritance

Inheritance diagram of Invite
class discordaio.invite.InviteMetadata(inviter=None, uses=0, max_uses=0, max_age=0, temporary=False, created_at=None, revoked=False)[source]

Represents the invite metadata

New in version 0.2.0.

inviter

A – user object user who created the invite

uses

int – number of times this invite has been used

max_uses

int – max number of times this invite can be used

max_age

int – duration (in seconds) after which the invite expires

temporary

bool – whether this invite only grants temporary membership

created_at

int – timestamp when this invite was created

revoked

bool – whether this invite is revoked

Inheritance

Inheritance diagram of InviteMetadata
discordaio.role
Classes
  • Role: Represents a discord role
class discordaio.role.Role(id=0, name='', color=0, hoist=False, position=0, permissions=0, managed=False, mentionable=False)[source]

Represents a discord role

New in version 0.2.0.

id

int – role id

name

str – role name

color

int – integer representation of hexadecimal color code

hoist

bool – if this role is pinned in the user listing

position

int – position of this role

permissions

int – permission bit set

managed

bool – whether this role is managed by an integration

mentionable

bool – whether this role is mentionable

Inheritance

Inheritance diagram of Role
discordaio.user

Users in Discord are generally considered the base entity. Users can spawn across the entire platform, be members of guilds, participate in text and voice chat, and much more. Users are separated by a distinction of “bot” vs “normal.” Although they are similar, bot users are automated users that are “owned” by another user. Unlike normal users, bot users do not have a limitation on the number of Guilds they can be a part of.

Classes
class discordaio.user.User(id=0, username='', discriminator='', avatar='', bot=False, mfa_enabled=False, verified=False, email='')[source]

Represents a discord user

New in version 0.2.0.

id

int – the user’s id identify

username

str – the user’s username, not unique across the platform identify

discriminator

str – the user’s 4-digit discord-tag identify

avatar

str – the user’s avatar hash identify

bot

bool, optional – whether the user belongs to an OAuth2 application identify

mfa_enabled

bool, optional – whether the user has two factor enabled on their account identify

verified

bool, optional – whether the email on this account has been verified email

email

str, optional – the user’s email email

Inheritance

Inheritance diagram of User
class discordaio.user.UserConnection(id='', name='', type='', revoked=False, integrations=[])[source]

Represents a discord user connection

New in version 0.2.0.

id

str – id of the connection account

name

str – the username of the connection account

type

str – the service of the connection (twitch, youtube)

revoked

bool – whether the connection is revoked

integrations

list – an array of partial server integrations

Inheritance

Inheritance diagram of UserConnection
discordaio.version
Variables
discordaio.version.__version__

str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’. .. code-block:: guess

‘0.2.1’
discordaio.voice
Classes
class discordaio.voice.VoiceState(guild_id: typing.Union[int, NoneType] = None, channel_id: int = 0, user_id: int = 0, session_id: str = '', deaf=False, mute=False, self_deaf=False, self_mute=False, suppress=False)[source]

Used to represent a user’s voice connection status.

guild_id

int, optional – the guild id this voice state is for

channel_id

int – the channel id this user is connected to

user_id

int – the user id this voice state is for

session_id

str – the session id for this voice state

deaf

bool – whether this user is deafened by the server

mute

bool – whether this user is muted by the server

self_deaf

bool – whether this user is locally deafened

self_mute

bool – whether this user is locally muted

suppress

bool – whether this user is muted by the current user

Inheritance

Inheritance diagram of VoiceState
class discordaio.voice.VoiceRegion(id='', name='', vip=False, optimal=False, deprecated=False, custom=False)[source]
id

str – unique ID for the region

name

str – name of the region

vip

bool – true if this is a vip-only server

optimal

bool – true for a single server that is closest to the current user’s client

deprecated

bool – whether this is a deprecated voice region (avoid switching to these)

custom

bool – whether this is a custom voice region (used for events/etc)

Inheritance

Inheritance diagram of VoiceRegion
discordaio.webhook

Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use.

Classes
  • Webhook: Used to represent a webhook.
class discordaio.webhook.Webhook(id=0, guild_id=0, channel_id=0, user=None, name='', avatar='', token='')[source]

Used to represent a webhook.

New in version 0.2.0.

id

int – the id of the webhook

guild_id

int, optional – the guild id this webhook is for

channel_id

int – the channel id this webhook is for

user

User – the user this webhook was created by (not returned when getting a webhook with its token)

name

str – the default name of the webhook

avatar

str – the default avatar of the webhook

token

str – the secure token of the webhook

Inheritance

Inheritance diagram of Webhook
discordaio.websocket
Classes
  • DiscordWebsocket: Class used for handling the websocket connection with the discord gateway
class discordaio.websocket.DiscordWebsocket(http: discordaio.http.HTTPHandler = None, session_id: str = None, shards: list = [])[source]

Class used for handling the websocket connection with the discord gateway

New in version 0.2.0.

heartbeat_interval

float – The interval to send pings

_trace

str – Used for debugging

seq

str – Used in pings

session_id

str – Used for resuming

http

HTTPHandler – Used for sending http requests and session handling.

gateway_url

str – The gateway url

shards

list of int – Used for opening multiple connections

ws (

class:aiohttp.ClientWebSocketResponse``): The websocket

Inheritance

Inheritance diagram of DiscordWebsocket
await close() → bool[source]

Closes the websocket

New in version 0.2.0.

Returns:True if succeded closing. False if the websocket was already closed
Return type:bool
await start()[source]

Starts the websocket

New in version 0.2.0.

Changelog

Version 0.2.0

  • All discord events can be used now.

Version 0.1.0

  • Initial development version

Indices and tables