Discord Models

This page provides a breakdown of the Discord data classes used by starlette_discord.

DiscordObject

class starlette_discord.DiscordObject(data)

Represents a Discord object. This library’s equivalent to discord.Object.

id

The Discord object’s unique ID.

Type:

int

classmethod from_id(id_: int)

Initializes a new DiscordObject with the given ID.

Note

Most people will never have to use this method. It is provided for cases where you only need an object with a specific ID.

Parameters:

id (int) – The ID of the object to create.

json()

Returns the original JSON data for this model.

Converting to Discord.py Objects

DiscordObject subclasses (User and Guild) can be converted to discord.X objects with the to_dpy method. While discord.py is not a dependency of this library, the client passed into this method should be a valid discord.py client. Specifically, it needs to implement the get_X and fetch_X methods.

This method is, and should remain, compatible with both discord.py 1.X and 2.X.

User

class starlette_discord.User(*, data)

A user model from Discord. Returned by session.identify().

id

The user’s unique ID.

Type:

int

username

The user’s username.

Type:

str

discriminator

The user’s discriminator.

Type:

str

avatar

The user’s avatar hash.

Type:

str

flags

The flags on the user’s account

Type:

int

public_flags

The public flags on the user’s account.

Type:

int

banner

The user’s banner hash.

Type:

str

banner_color

The user’s banner color.

Type:

str

accent_color

The user’s banner color: represented as the int form of the color’s hex code.

Type:

int

locale

The user’s language locale.

Type:

str

mfa_enabled

Whether the user has multi-factor authentication enabled.

Type:

bool

email

The user’s email address. Only provided if the email scope is authorized.

Type:

str

verified

Whether the user’s email address has been verified.

Type:

str

await to_dpy(client)

Tries to convert this User to a discord.User.

This is just a shortcut for client.get_user(id) followed by client.fetch_user(id), returning None if not found.

Note

A discord.py Client or Bot object must be passed into this function.

Parameters:

client (discord.Client) – The bot client to use to create the object.

Returns:

The discord.py User object, if it could be found.

Return type:

discord.User

Guild

class starlette_discord.Guild(*, data)

A partial guild model from Discord. Returned by session.guilds().

id

The guild’s unique ID.

Type:

int

name

The guild’s name.

Type:

str

icon

The guild’s icon hash.

Type:

str

owner

Whether the authorized user is owner of this guild.

Type:

bool

permissions

The authorized user’s permissions in this guild.

Type:

int

features

The guild’s enabled features.

Type:

List[str]

await to_dpy(client)

Tries to convert this Guild to a discord.Guild.

This is just a shortcut for client.get_guild(id) followed by client.fetch_guild(id), returning None if not found.

Note

A discord.py Client or Bot object must be passed into this function.

Parameters:

client (discord.Client) – The bot client to use to create the object.

Returns:

The discord.py Guild object, if the guild could be found.

Return type:

discord.Guild

Connection

class starlette_discord.Connection(*, data)

An account connection model from Discord.

type

The connection type.

Type:

str

id

The connected account’s ID.

Type:

str

name

The connected account’s username.

Type:

str

visibility

The connected account’s visibility.

Type:

int

friend_sync

Whether friend sync is enabled for this connected account.

Type:

bool

show_activity

Whether activities related to this connection will be shown in presence updates.

Type:

bool

verified

Whether this connected account is verified.

Type:

bool

json()

Returns the original JSON data for this model.