API Reference

The following section covers the API of DisCode.

Clients

These are the clients, that the library provides.

Client

class discode.Client(**kwargs)

Represents the client that connects to the Discord API and the Gateway

Parameters
  • message_limit (int) – The maximum amount of messages to have in the cache. Messages are cached to reduce api callsand prevent ratelimits.

  • chunk_at_startup (bool) – If the client should chunk up all the guild members before the ready event. Defaults to True.

loop

The asyncio.AbstractEventLoop to be used for asynchronous functions.

Type

asyncio.AbstractEventLoop

guilds

The guild cache of the client

Type

List[Guild]

active_interactions

Contains all the component interactions that the client is listening for.

Type

List[Any]

property user

Returns the ClientUser connected to the Discord Gateway.

property is_ready

Retruns a True if the Client is ready, else False

Returns

The ready state of the client.

Return type

bool

property latency

Returns the latency of the websocket connection with the Discord Gateway.

Returns

The latency of the client in float

Return type

float

async error(event, exception)

The default error handler of the client.

on_event(event_name, name=None)

The decorator that registers a new listener

add_listener(event_name, name, callback)

This used by the on_event() decorator to register a new listener, this can also be used to add listeners manually. The callback must be a coroutine.

async start_task(token)

A coroutine to start the bot. It is recommended to use the start method if you do not know what you are doing.

start(token)

Connects to the Discord Gateway along with the REST API. It is recommended to use this function to start your bot / client.

get_channel(channel_id, guild_id)

Get a Channel from the client’s cache. Returns None if the channel doesnt’t exist or if the cache hasn’t been updated yet. In this case, fetch_channel() can be used.

Returns

Returns the channel object or None if its not found.

Return type

Union[TextChannel, Channel]

get_member(member_id, guild_id)

Returns a Member object if the user is found, else None

Returns

The member object that you searched for.

Return type

Member

get_guild(guild_id)

Returns a Guild object if the guild exists, else None . There is almost no way, that this misses an existing guild.

Bots

These are the Bot objects, that the library provides.

Bot

class discode.Bot(**kwargs)

Represents the bot that connects to Discord.

Event Reference

This section covers Discord gateway events and custom DisCode events. You can register an event liestener by using Client.on_event()

Example:

@client.on_event("ready")
async def ready_event():
   print(client.user, "is ready!")

Discord Objects

Discord Objects are objects, that the library provides you with to use. Some common examples of these are Message, Channel, etc. These classes are not to be initialised by users, except for a few, for example Embed and Intents. All the classes that are not supposed to be initialised by users are marked with a warning sign.

Message Object

Warning

This class should not be initialised by users.

class discode.Message(**data)

Represents a Discord message.

property author

The person who created the message. Returns a Member if the message was sent in a guild. If it wasn’t, for example a DM, it returns a User object.

Returns

The user or member who created the object.

Return type

Union[User, Member]

property guild

Returns the guild to which the message belongs to. If the guild doesn’t exist, it returns None

Returns

The Discord server to which the message belongs.

Return type

Guild

Embed Object

class discode.Embed(title=None, description=None, colour=None)

Represents a Discord embed. This part of a Message.

title

The title of the embed.

Type

Optional[str]

description

The description of the embed.

Type

Optional[str] = None

colour

The colour of the embed.

Type

Optional[Union[Colour, hex, int]] = None

color

The colour of the embed.

Type

Optional[Union[Colour, hex, int]] = colour

fields

The list of all the fields of the embed.

Type

List[dict]

add_field(name, value, inline=True)

Add a field to the embed object.

Returns

The embed object to which the field was added to.

Return type

Embed

Set a footer for the embed.

Returns

The embed to which the field was added to.

Return type

Embed