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.
- 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().- accent_color¶
The user’s banner color: represented as the int form of the color’s hex code.
- Type:
- await to_dpy(client)¶
Tries to convert this User to a
discord.User.This is just a shortcut for
client.get_user(id)followed byclient.fetch_user(id), returningNoneif not found.Note
A discord.py
ClientorBotobject 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:
Guild¶
- class starlette_discord.Guild(*, data)¶
A partial guild model from Discord. Returned by
session.guilds().- permissions¶
The authorized user’s permissions in this guild.
- Type:
- await to_dpy(client)¶
Tries to convert this Guild to a
discord.Guild.This is just a shortcut for
client.get_guild(id)followed byclient.fetch_guild(id), returningNoneif not found.Note
A discord.py
ClientorBotobject 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:
Connection¶
- class starlette_discord.Connection(*, data)¶
An account connection model from Discord.
- visibility¶
The connected account’s visibility.
- Type:
- show_activity¶
Whether activities related to this connection will be shown in presence updates.
- Type:
- json()¶
Returns the original JSON data for this model.