Adapt.py API Reference#
Client and Events#
Client#
- class adapt.Client(*, loop=None, session=None, server=('https://api.adapt.chat', 'wss://harmony.adapt.chat', 'https://convey.adapt.chat'), token=None, status=Status.online)#
Represents a client that interacts with Adapt.
This class inherits from
EventDispatcher
. See the documentation for that class for documentation on event listeners.- loop#
The asyncio event loop the client uses.
- http#
The HTTP client utilized by this client that interacts with Adapt HTTP requests.
- Type:
HTTPClient
- ws#
The websocket client utilized by this client that interacts with Adapt websocket events.
- Type:
WebSocket
- Parameters:
loop (
asyncio.AbstractEventLoop
) – The event loop the client should use. Defaults to what is returned by callingasyncio.get_event_loop()
.session (
aiohttp.ClientSession
) – The aiohttp client session to use for the created HTTP client. If not provided, one is created for you.server (
AdaptServer
) – The urls of the backend server. Defaults to the production server found at adapt.chat.token (
str
) – The token to run the client with. Leave blank to delay specification of the token.status (
Status
) – The status to set the client to when it connects to harmony. Defaults toStatus.online
.
- async close()#
This function is a coroutine.
Closes the client, freeing up resources the client might have used. This is automatically called if you use
run()
.
- property connection#
The connection object that manages the connection to Adapt and cached models.
- Type:
Connection
- async create_guild(*, name, description=None, icon=None, banner=None, public=False, nonce=None)#
This function is a coroutine.
Creates a new guild.
- Parameters:
name (
str
) – The name of the guild.description (
str
) – The description of the guild. This is optional.icon (
bytes
, path-like object, file-like object, orNone
) – The icon of the guild. This is optional.banner (
bytes
, path-like object, file-like object, orNone
) – The banner of the guild. This is optional.public (
bool
) – Whether the guild should be public. Defaults toFalse
.nonce (
str
) – An optional nonce for integrity. When the guild creation event is received through the websocket, the nonce will be included in the payload. This can be used to verify that the guild was created successfully.
- Returns:
The guild that was created.
- Return type:
- classmethod create_user(*, username, display_name=None, email, password, server=('https://api.adapt.chat', 'wss://harmony.adapt.chat', 'https://convey.adapt.chat'), **options)#
This function is a coroutine.
Registers a new user account, and returns a new client created to interact with that account.
When using this in a context manager,
async with await
is unnecessary# Recommended: async with Client.create_user(...) as client: await client.start(TOKEN) # Unnecessary: async with await Client.create_user(...) as client: await client.start(TOKEN)
Otherwise, this should be treated as a coroutine:
client = await Client.create_user(...) client.run(TOKEN)
- Parameters:
username (
str
) – The username of the new account.display_name (
str
orNone
) – The display name of the new account. Defaults toNone
(i.e. no display name).email (
str
) – The email of the new account.password (
str
) – The password of the new account.server (
AdaptServer
) – The urls of the backend server. Defaults to the production server found at adapt.chat.**options – Additional keyword-arguments to pass in when constructing the HTTP client (i.e. loop, session)
- Returns:
The created client object.
- Return type:
- async fetch_guild(guild_id, *, respect_cache=False, channels=False, members=False, roles=False)#
This function is a coroutine.
Fetches a guild directly from the API.
- Parameters:
guild_id (
int
) – The guild ID to fetch.respect_cache (
bool
) – IfTrue
, if the guild is found in the cache, it will be returned instead of fetching from the API. This will also mean themembers
,roles
, andchannels
parameters will be ignored.channels (
bool
) – IfTrue
, the guild’s channels will be fetched.members (
bool
) – IfTrue
, the guild’s members will be fetched.roles (
bool
) – IfTrue
, the guild’s roles will be fetched.
- Returns:
The guild object that was fetched.
- Return type:
- async fetch_guilds(*, channels=False, members=False, roles=False)#
This function is a coroutine.
Fetches all guilds that the client is a member of.
Warning
This is an expensive process and has high ratelimits, so it should be used sparingly. Guild data is returned by the ready event, so it is usually unnecessary to call this method.
- async fetch_relationships()#
This function is a coroutine.
Fetches all relationships between the client and other users directly from the API.
- Returns:
An iterable of relationship objects that were fetched. This is a generator that lazily resolves the relationships into
Relationship
objects.- Return type:
Iterable[
Relationship
]
- async fetch_user(user_id, *, respect_cache=False)#
This function is a coroutine.
Fetches a user directly from the API.
- classmethod from_http(http, *, server=None, **kwargs)#
Creates a client from an HTTP client. This is used internally.
- Parameters:
http (
HTTPClient
) – The HTTP client to create the client object with.server (
AdaptServer
) – The urls of the backend server. Defaults to the production server found at adapt.chat.**kwargs – Additional keyword arguments to pass into the client constructor.
- Returns:
The created client object.
- Return type:
- classmethod from_login(*, email, password, method='reuse', server=('https://api.adapt.chat', 'wss://harmony.adapt.chat', 'https://convey.adapt.chat'), **options)#
This function is a coroutine.
Logs in with the specified credentials, then returns a client to interact with that account.
When using this in a context manager,
async with await
is unnecessary# Recommended: async with Client.from_login(...) as client: await client.start(TOKEN) # Unnecessary: async with await Client.from_login(...) as client: await client.start(TOKEN)
Otherwise, this should be treated as a coroutine:
client = await Client.from_login(...) client.run(TOKEN)
- Parameters:
email (
str
) – The email of the account.password (
str
) – The password of the account.method (Literal['new', 'revoke', 'reuse']) – The method to use to retrieve the token. Defaults to ‘reuse’.
server (
AdaptServer
) – The urls of the backend server. Defaults to the production server found at adapt.chat.**options – Additional keyword-arguments to pass in when constructing the HTTP client (i.e. loop, session)
- Returns:
The created client object.
- Return type:
- get_guild(guild_id)#
Retrieves a guild from the cache.
- get_partial_guild(guild_id)#
Creates a usable partial guild object that operates with only its ID.
This is useful for when you want to perform actions on a guild without having to ensure it is cached or fetch unnecessary guild data.
- Parameters:
guild_id (
int
) – The guild ID to create the partial guild with.- Returns:
The partial guild object that was created.
- Return type:
- get_partial_user(user_id)#
Creates a usable partial user object that operates with only its ID.
This is useful for when you want to perform actions on a user without having to ensure they are cached or fetch unnecessary user data.
- Parameters:
user_id (
int
) – The user ID to create the partial user with.- Returns:
The partial user object that was created.
- Return type:
- get_relationship(user_id)#
Retrieves the relationship between the client and the user with the given ID from the cache.
- Parameters:
user_id (
int
) – The user ID to retrieve.- Returns:
The relationship object that was retrieved, or
None
if no relationship was found.- Return type:
- get_user(user_id)#
Retrieves a user from the cache.
- property latency#
The amount of time in seconds it took for the previous heartbeat to harmony (the websocket) to be acknowledged.
This is
None
if: - The client is not logged in. - The client has not yet sent a heartbeat to harmony. - The client has not yet received a heartbeat acknowledgement from harmony.- Type:
- property latency_ns#
The equivalent of
latency
but in nanoseconds. This could yield more accurate measurements due to floating point precision errors inlatency
.See also
latency
The equivalent of this property in seconds. See this for more information.
- Type:
- property relationships#
An iterable of relationships that the client has cached.
- Type:
Iterable[
Relationship
]
- run(token=None)#
Runs the client, logging in with the provided token and connecting to harmony. This is a blocking call.
- Parameters:
token (
str
) – The token to log in with. If not provided, the token specified in the constructor is used.
- property server#
The server the client retrieves all Adapt URLs from.
- async start(token=None)#
This function is a coroutine.
Starts the client, logging in with the provided token and connecting to harmony.
- Parameters:
token (
str
) – The token to log in with. If not provided, the token specified in the constructor is used.
- async update_presence(*, status=...)#
This function is a coroutine.
Updates the client’s presence.
- Parameters:
status (
Status
) – The new status to update the client’s presence with. Leave blank to keep the current status.
- property user#
The user object that represents the user account the client is logged into.
This is
None
if the client is not logged in.- Type:
ClientUser
| None
Server#
- class adapt.AdaptServer(api, harmony, convey)#
Represents connection URLs or locations of the Adapt API server.
- Parameters:
api (
str
) – The URL of the HTTP REST API. (e.g. https://api.adapt.chat)harmony (
str
) – The URL of the websocket API. (e.g. wss://harmony.adapt.chat)convey (
str
) – The URL of the file upload and CDN API. (e.g. https://convey.adapt.chat)
- api#
Alias for field number 0
- convey#
Alias for field number 2
- copy_with(*, api=None, harmony=None, convey=None)#
Create a copy of this
AdaptServer
with the specified parameters replaced.- Parameters:
api (
str
) – The URL of the HTTP REST API. (e.g. https://api.adapt.chat)harmony (
str
) – The URL of the websocket API. (e.g. wss://harmony.adapt.chat)convey (
str
) – The URL of the file upload and CDN API. (e.g. https://convey.adapt.chat)
- harmony#
Alias for field number 1
- classmethod local()#
A
AdaptServer
instance representing a local Adapt API server with default ports extracted from Adapt’s source code.This is useful for testing.
- classmethod production()#
A
AdaptServer
instance representing the production Adapt API server (adapt.chat).This is the default server used by the library.
Events#
- class adapt.client.EventDispatcher#
Base class for receiving events and then dispatching them to event handlers registered on the client.
- dispatch(event, *args, **kwargs)#
Dispatches an event to its registered listeners.
- Parameters:
event (
str
) – The event to dispatch to.*args – Positional arguments to pass into event handlers.
**kwargs – Keyword arguments to pass into event handlers.
- event(callback)#
Registers an event listener on the client. This overrides any previous listeners for that event.
- listen(*events, check=None, timeout=None, limit=None)#
Registers a weak listener for the given events. You may register as many of these as you want.
- Parameters:
*events (
str
) – The events to listen for.check (((*P.args, **P.kwargs) ->
bool
) | None) – An event check for when to call the callback. Leave empty to not have a check.timeout (
float
| None) – The amount of seconds before this listener should expire. Leave empty to not have a timeout.limit (
int
| None) – The amount of times the callback should be called before this listener should expire. Leave empty to not have a limit.
- async on_connect()#
This function is a coroutine.
Called when the client establishes a connection with the websocket.
- async on_event(event, *args, **kwargs)#
This function is a coroutine.
A “catch all” event handler for all events.
- Parameters:
event (
str
) – The name of the event.*args (Any) – The positional arguments for the event.
**kwargs (Any) – The keyword arguments for the event.
- async on_guild_create(guild)#
This function is a coroutine.
Called when a guild is created.
- Parameters:
guild (
Guild
) – The guild that was created.
- async on_message(message)#
This function is a coroutine.
Called when a message is created.
- Parameters:
message (
Message
) – The message that was created.
- async on_ready(ready)#
This function is a coroutine.
Called when the client is connected and ready to receive events from the websocket.
- Parameters:
ready (
ReadyEvent
) – Data received with the ready event.
- async on_start()#
This function is a coroutine.
Called when the client starts to connect. This can be used to perform any necessary setup.
- async wait_for(*events, check=None, timeout=None)#
This function is a coroutine.
Waits for an event to be dispatched.
- Parameters:
- Raises:
asyncio.TimeoutError – The event was not dispatched within the given timeout.
- Returns:
The positional arguments of the dispatched event.
- Return type:
*P.args
Event Utilities#
- adapt.once(func)#
A decorator that registers an event listener to be called only once before being destroyed. This can be used within the client class.
Usage:
from adapt import Client, ReadyEvent, once class MyClient(Client): @once async def on_ready(self, _event: ReadyEvent): print('Ready!')
- class adapt.ReadyEvent(*, connection, data)#
Represents the ready event from the gateway. This event is sent when the client is ready to receive events.
Note
Just like all models, this class is not meant to be constructed by the user. However, if for some reason you need to construct this class, it should be known that the constructor mutates the given connection state, which could lead to unexpected behaviour.
- user#
The client user object.
- Type:
- presences#
A list of presences the client has.
- Type:
list[
Presence
]
- relationships#
A list of relationships the client has with other users.
- Type:
list[
Relationship
]
Models#
Object#
User#
- class adapt.User#
Represents an Adapt user.
- async accept_friend_request()#
This function is a coroutine.
Accepts the incoming friend request from this user.
- Returns:
The relationship created from accepting the friend request.
- Return type:
- Raises:
TypeError – If there is no incoming friend request from this user.
- async block()#
This function is a coroutine.
Blocks this user.
- Returns:
The relationship created from blocking the user.
- Return type:
- async create_dm()#
This function is a coroutine.
Creates a DM channel with this user. This makes the API call despite whether a DM channel already exists.
- Returns:
The DM channel created.
- Return type:
- property created_at#
The time the object was created.
- async decline_friend_request()#
This function is a coroutine.
Declines the incoming friend request from this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no incoming friend request from this user.
- property display_name#
The name displayed to refer to the user globally.
This falls back to
username
if the user has no display name.- Type:
- property id#
The ID of the object.
- property name#
The user’s username. This is an alias for
username
.Deprecated since version 0.1.0: This property is officially named
username
and it is a good practice to use that instead of “name”.- Type:
- property relationship#
The relationship between you and this user.
Returns
None
if no relationship exists.- Type:
- async remove_friend()#
This function is a coroutine.
Removes this user as a friend. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not a friend.
- property resolved_name#
The resolved name for the user, displayed in clients to refer to the user.
For users, this is the same as
display_name
.For members, this returns the user’s nickname with a fallback to
display_name
.
- Type:
- async revoke_friend_request()#
This function is a coroutine.
Revokes the outgoing friend request to this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no outgoing friend request to this user.
- async send(content=None, *, nonce=None)#
This function is a coroutine.
Sends a message to the channel.
- Parameters:
- Returns:
The message that was sent.
- Return type:
- async send_friend_request()#
This function is a coroutine.
Sends a friend request to this user.
- Returns:
The relationship created from sending the friend request.
- Return type:
- async unblock()#
This function is a coroutine.
Unblocks this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not blocked.
ClientUser#
- class adapt.ClientUser#
Represents the user object for the client user.
- property created_at#
The time the object was created.
- async delete(*, password)#
This function is a coroutine.
Deletes the client’s user account. This is irreversible.
Note
The account must be a user account; if it is a bot account, the bot account can only be deleted by the user account that owns it.
- property display_name#
The name displayed to refer to the user globally.
This falls back to
username
if the user has no display name.- Type:
- async edit(*, username=..., display_name=..., avatar=..., banner=..., bio=...)#
This function is a coroutine.
Updates the client’s user information. Only the parameters passed will be updated.
- Parameters:
username (
str
) – The new username to use.display_name (
str
orNone
) – The new display name to use. IfNone
, the display name will be removed.avatar (
bytes
, path-like object, file-like object, orNone
) – The new avatar to use. IfNone
, the avatar will be removed.banner (
bytes
, path-like object, file-like object, orNone
) – The new banner to use. IfNone
, the banner will be removed.bio (
str
orNone
) – The new bio to use. IfNone
, the bio will be removed.
- Returns:
The updated client user.
- Return type:
- property id#
The ID of the object.
- property name#
The user’s username. This is an alias for
username
.Deprecated since version 0.1.0: This property is officially named
username
and it is a good practice to use that instead of “name”.- Type:
- property resolved_name#
The resolved name for the user, displayed in clients to refer to the user.
For users, this is the same as
display_name
.For members, this returns the user’s nickname with a fallback to
display_name
.
- Type:
PartialUser#
- class adapt.PartialUser#
A partial user object which operates with only an ID.
This is useful for performing operations on users without having to fetch them first.
- async accept_friend_request()#
This function is a coroutine.
Accepts the incoming friend request from this user.
- Returns:
The relationship created from accepting the friend request.
- Return type:
- Raises:
TypeError – If there is no incoming friend request from this user.
- async block()#
This function is a coroutine.
Blocks this user.
- Returns:
The relationship created from blocking the user.
- Return type:
- async create_dm()#
This function is a coroutine.
Creates a DM channel with this user. This makes the API call despite whether a DM channel already exists.
- Returns:
The DM channel created.
- Return type:
- property created_at#
The time the object was created.
- async decline_friend_request()#
This function is a coroutine.
Declines the incoming friend request from this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no incoming friend request from this user.
- property id#
The ID of the object.
- property relationship#
The relationship between you and this user.
Returns
None
if no relationship exists.- Type:
- async remove_friend()#
This function is a coroutine.
Removes this user as a friend. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not a friend.
- async revoke_friend_request()#
This function is a coroutine.
Revokes the outgoing friend request to this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no outgoing friend request to this user.
- async send(content=None, *, nonce=None)#
This function is a coroutine.
Sends a message to the channel.
- Parameters:
- Returns:
The message that was sent.
- Return type:
- async unblock()#
This function is a coroutine.
Unblocks this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not blocked.
Relationship#
- class adapt.Relationship#
Represents a relationship between you, the client user, and another user.
- async accept()#
This function is a coroutine.
Accepts this relationship if it is an incoming friend request. This is equivalent to calling
User.accept_friend_request()
.- Returns:
The relationship created from accepting the friend request.
- Return type:
- Raises:
TypeError – If the relationship type is not
incoming_request
.
- async delete()#
This function is a coroutine.
Deletes this relationship:
If the relationship type is
friend
, this will unfriend the user.If the relationship type is
outgoing_request
, this will cancel the outgoing friend request.If the relationship type is
incoming_request
, this will decline the incoming friend request.If the relationship type is
blocked
, this will unblock the user.
- property type#
The type of this relationship.
- Type:
Guild#
- class adapt.Guild#
Represents a guild in Adapt.
- vanity_code#
The vanity URL code of the guild. This solely includes the code, not the full URL. This is
None
if the guild does not have a vanity URL.- Type:
str
| None
- property cache_integrity#
Returns the integrity of the guild’s cache.
This is a
NamedTuple
with the following boolean attributes:members
: Whether the guild’s members are cached.roles
: Whether the guild’s roles are cached.channels
: Whether the guild’s channels are cached.
- property channels#
An iterable of the guild’s channels.
- Type:
Iterable[
GuildChannel
]
- property created_at#
The time the object was created.
- async delete(*, password=...)#
This function is a coroutine.
Deletes the guild.
- Parameters:
password (
str
) – Your account password. This must be specified when deleting user accounts for security purposes. This should not be specified when deleting bot accounts.
- async edit(*, name=..., description=..., icon=..., banner=..., public=...)#
This function is a coroutine.
Edits the properties for the guild. Only the parameters passed will be updated.
- Parameters:
name (
str
) – The new name for the guild.description (
str
) – The new description for the guild. Set toNone
to remove the description.icon (
bytes
, path-like object, file-like object, orNone
) – The new icon for the guild. Set toNone
to remove the icon.banner (
bytes
, path-like object, file-like object, orNone
) – The new banner for the guild. Set toNone
to remove the banner.public (
bool
) – Whether the guild is public or not.
- Returns:
The updated guild object.
- Return type:
- async fetch_channel(channel_id, *, respect_cache=True)#
This function is a coroutine.
Fetches the channel with the given ID from the API.
- Parameters:
- Returns:
The channel with the given ID.
- Return type:
- async fetch_member(member_id, *, respect_cache=True)#
This function is a coroutine.
Fetches the member with the given ID from the API.
- property flags#
Special properties and features about the guild.
- Type:
- get_channel(channel_id)#
Returns the channel with the given ID, resolved from the cache.
- Parameters:
channel_id (
int
) – The ID of the channel to get.- Returns:
The channel with the given ID, or
None
if not found in the cache.- Return type:
GuildChannel
| None
- get_member(member_id)#
Returns the member with the given ID, resolved from the cache.
- get_partial_member(member_id)#
Creates a usable partial member object that operates with only its ID.
This is useful for when you want to perform actions on a member without having to ensure it is cached or fetch unnecessary guild or member data.
- Parameters:
member_id (
int
) – The user ID to create the partial member with.- Returns:
The partial member object that was created.
- Return type:
- property id#
The ID of the object.
- async kick(member)#
This function is a coroutine.
Kicks the member from the guild. You must have the
Permissions.kick_members
permission to do this.- Parameters:
member (
Member
-like) – The member to kick.
- property me#
The member that represents the client in the guild, if available in cache.
This is equivalent to
guild.get_member(client.user.id)
.- Type:
- property owner#
The resolved member object of the guild owner, if available in cache.
- Type:
Member
| None
- property text_channels#
An iterator of the guild’s text-based channels.
- Type:
Iteratable[
TextBasedGuildChannel
]
PartialGuild#
- class adapt.PartialGuild#
A partial guild object which operates with only an ID.
This is useful for performing operations on guilds without having to fetch them first.
Note
Unlike a full
Guild
, partial guilds will not perform any permission checks locally and will instead rely on the API to perform them. This could result in more unnecessary API calls being made.Note
This is not to be confused with the official
PartialGuild
model in the Adapt API protocol, which is a guild without member, channel, and role data. This is a guild object that only operates with an ID.- property created_at#
The time the object was created.
- async delete(*, password=...)#
This function is a coroutine.
Deletes the guild.
- Parameters:
password (
str
) – Your account password. This must be specified when deleting user accounts for security purposes. This should not be specified when deleting bot accounts.
- async edit(*, name=..., description=..., icon=..., banner=..., public=...)#
This function is a coroutine.
Edits the properties for the guild. Only the parameters passed will be updated.
Note
Nothing is returned from this method. If you wish to get the updated guild object, perform the edit on a full
Guild
object instead.- Parameters:
name (
str
) – The new name for the guild.description (
str
) – The new description for the guild. Set toNone
to remove the description.icon (
bytes
, path-like object, file-like object, orNone
) – The new icon for the guild. Set toNone
to remove the icon.banner (
bytes
, path-like object, file-like object, orNone
) – The new banner for the guild. Set toNone
to remove the banner.public (
bool
) – Whether the guild is public or not.
- get_partial_member(member_id)#
Creates a usable partial member object that operates with only its ID.
This is useful for when you want to perform actions on a member without having to ensure it is cached or fetch unnecessary guild or member data.
- Parameters:
member_id (
int
) – The user ID to create the partial member with.- Returns:
The partial member object that was created.
- Return type:
- property id#
The ID of the object.
- async kick(member)#
This function is a coroutine.
Kicks the member from the guild. You must have the
Permissions.kick_members
permission to do this.- Parameters:
member (
Member
-like) – The member to kick.
Member#
- class adapt.Member#
Represents a member of a guild.
- async accept_friend_request()#
This function is a coroutine.
Accepts the incoming friend request from this user.
- Returns:
The relationship created from accepting the friend request.
- Return type:
- Raises:
TypeError – If there is no incoming friend request from this user.
- async block()#
This function is a coroutine.
Blocks this user.
- Returns:
The relationship created from blocking the user.
- Return type:
- async create_dm()#
This function is a coroutine.
Creates a DM channel with this user. This makes the API call despite whether a DM channel already exists.
- Returns:
The DM channel created.
- Return type:
- property created_at#
The time the object was created.
- async decline_friend_request()#
This function is a coroutine.
Declines the incoming friend request from this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no incoming friend request from this user.
- property display_name#
The name displayed to refer to the user globally.
This falls back to
username
if the user has no display name.- Type:
- property id#
The ID of the object.
- property is_me#
Whether this member is the client user.
- async kick()#
This function is a coroutine.
Kicks the member from the guild. You must have the
Permissions.kick_members
permission to do this. This is a shortcut for callingGuild.kick()
with this member.
- property name#
The user’s username. This is an alias for
username
.Deprecated since version 0.1.0: This property is officially named
username
and it is a good practice to use that instead of “name”.- Type:
- property relationship#
The relationship between you and this user.
Returns
None
if no relationship exists.- Type:
- async remove_friend()#
This function is a coroutine.
Removes this user as a friend. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not a friend.
- property resolved_name#
The member’s display name.
This is their nickname if they have one, otherwise it is their
display_name
.- Type:
- async revoke_friend_request()#
This function is a coroutine.
Revokes the outgoing friend request to this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no outgoing friend request to this user.
- async send(content=None, *, nonce=None)#
This function is a coroutine.
Sends a message to the channel.
- Parameters:
- Returns:
The message that was sent.
- Return type:
- async send_friend_request()#
This function is a coroutine.
Sends a friend request to this user.
- Returns:
The relationship created from sending the friend request.
- Return type:
- async unblock()#
This function is a coroutine.
Unblocks this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not blocked.
PartialMember#
- class adapt.PartialMember#
Represents a partial member of a guild.
This is useful for performing operations on members without having to fetch them first.
- guild#
The guild that the member is in. This may be a partial guild.
- Type:
- async accept_friend_request()#
This function is a coroutine.
Accepts the incoming friend request from this user.
- Returns:
The relationship created from accepting the friend request.
- Return type:
- Raises:
TypeError – If there is no incoming friend request from this user.
- async block()#
This function is a coroutine.
Blocks this user.
- Returns:
The relationship created from blocking the user.
- Return type:
- async create_dm()#
This function is a coroutine.
Creates a DM channel with this user. This makes the API call despite whether a DM channel already exists.
- Returns:
The DM channel created.
- Return type:
- property created_at#
The time the object was created.
- async decline_friend_request()#
This function is a coroutine.
Declines the incoming friend request from this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no incoming friend request from this user.
- property id#
The ID of the object.
- property is_me#
Whether this member is the client user.
- async kick()#
This function is a coroutine.
Kicks the member from the guild. You must have the
Permissions.kick_members
permission to do this. This is a shortcut for callingGuild.kick()
with this member.
- property relationship#
The relationship between you and this user.
Returns
None
if no relationship exists.- Type:
- async remove_friend()#
This function is a coroutine.
Removes this user as a friend. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not a friend.
- async revoke_friend_request()#
This function is a coroutine.
Revokes the outgoing friend request to this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If there is no outgoing friend request to this user.
- async send(content=None, *, nonce=None)#
This function is a coroutine.
Sends a message to the channel.
- Parameters:
- Returns:
The message that was sent.
- Return type:
- async unblock()#
This function is a coroutine.
Unblocks this user. This is a checked-equivalent of
Relationship.delete()
.- Raises:
TypeError – If this user is not blocked.
PartialMessageable#
- class adapt.PartialMessageable#
Represents a channel tha t can be a medium for text-based communication that operates with only its channel ID.
This is useful for performing messaging operations on channels without having to fetch them first or guarantee that they are cached.
TextChannel#
- class adapt.TextChannel#
Represents a text-based guild channel in Adapt.
- locked#
Whether the channel is locked. Only people with the
manage_channels
permission can send messages in locked channels.- Type:
- property created_at#
The time the object was created.
- async delete()#
This function is a coroutine.
Deletes the channel. You must have the
manage_channels
permission to do this.
- property id#
The ID of the object.
- property is_locked#
Whether the channel is locked.
This is an alias for
locked
. and is provided for consistency.- Type:
- property is_nsfw#
Whether the channel is NSFW.
This is an alias for
nsfw
. and is provided for consistency.- Type:
- async send(content=None, *, nonce=None)#
This function is a coroutine.
Sends a message to the channel.
- Parameters:
- Returns:
The message that was sent.
- Return type:
- property slowmode#
The slowmode of the channel, in seconds. This is
0.0
if the channel has no slowmode.- Type:
AnnouncementChannel#
- class adapt.AnnouncementChannel#
Represents an announcement channel in a guild in Adapt.
- property created_at#
The time the object was created.
- async delete()#
This function is a coroutine.
Deletes the channel. You must have the
manage_channels
permission to do this.
- property id#
The ID of the object.
- property is_locked#
Whether the channel is locked.
This is an alias for
locked
. and is provided for consistency.- Type:
- property is_nsfw#
Whether the channel is NSFW.
This is an alias for
nsfw
. and is provided for consistency.- Type:
- async send(content=None, *, nonce=None)#
This function is a coroutine.
Sends a message to the channel.
- Parameters:
- Returns:
The message that was sent.
- Return type:
- property slowmode#
The slowmode of the channel, in seconds. This is
0.0
if the channel has no slowmode.- Type:
DMChannel#
- class adapt.DMChannel#
Represents a DM channel in Adapt.
- type#
The type of the channel.
is_dm
for this value will always beTrue
.- Type:
- property can_manage#
Whether the client can manage the channel.
This will always be
True
for DM channels.- Type:
- property created_at#
The time the object was created.
- property id#
The ID of the object.
- property recipient#
The other recipient of this DM channel.
This is a shortcut for calling
Connection.get_user()
withrecipient_id
. If the user is not cached, this will returnNone
.- Type:
- property recipients#
The recipients of the channel, including yourself.
This is a shortcut for calling
Connection.get_user()
with each ID inrecipient_ids
. Users that are not cached will be excluded from the list.- Type:
list`[:class:
.User`]
Message#
- class adapt.Message#
Represents a message in Adapt.
- type#
The type of the message.
- Type:
- flags#
Special properties about the message.
- Type:
- property author#
The author of the message.
If an author is not applicable, or resolved author data was not provided and the author is not cached, this will be
None
.Otherwise, if the message was sent in a guild, this will be a
Member
. If it was sent in a private channel, this will be aUser
.
- property created_at#
The time the object was created.
- property id#
The ID of the object.
PartialMessage#
- class adapt.PartialMessage(*, channel, id)#
Represents a message in Adapt that only operates with a channel, message ID, and potentially a revision ID.
This is useful for performing operations on messages without having to fetch them first.
- channel#
The channel that the message belongs to.
- Type:
- property created_at#
The time the object was created.
- property id#
The ID of the object.
Asset#
- class adapt.Asset#
Represents an asset from Adapt’s CDN, convey.
- async read(*, cache=True)#
This function is a coroutine.
Downloads the asset’s contents into raw bytes. This cannot be used if the asset is stateless.
Note
For assets that are cached, the cache is held on the asset object and not the connection. This means that two different asset objects may not share the same cache.
- async save(fp, *, cache=True, seek_begin=True)#
This function is a coroutine.
Downloads the asset’s contents and saves it to a file. This cannot be used if the asset is stateless.
Note
For assets that are cached, the cache is held on the asset object and not the connection. This means that two different asset objects may not share the same cache.
- Parameters:
fp (
str
,pathlib.Path
, or file-like object) – The file path or file-like object to save the asset to.cache (
bool
) – Whether to cache the asset. Defaults toTrue
. If this is enabled, future calls tosave
will not download the asset again.seek_begin (
bool
) – Whether to seek to the beginning of the file after writing. Defaults toTrue
.
- Returns:
The number of bytes written to the file.
- Return type:
- Raises:
If the file-like object does not support the
write
method. - If the asset is stateless.
Base Classes#
Messageable#
- class adapt.Messageable#
Represents a channel or model that can be a medium for text-based communication.
GuildChannel#
- class adapt.GuildChannel#
Represents a guild channel in Adapt.
This is the base class for all types of guild channels, and should not be used directly.
Channels are the primary way to communicate with other users in Adapt. They can be either text-based, voice-based, or a category of channels.
- type#
The type of the channel.
ChannelType.is_guild
for this value will always beTrue
.- Type:
- position#
The position of the channel in the channel list. See the essence documentation for more information.
- Type:
- property created_at#
The time the object was created.
- async delete()#
This function is a coroutine.
Deletes the channel. You must have the
manage_channels
permission to do this.
- property id#
The ID of the object.
PrivateChannel#
- class adapt.PrivateChannel#
Represents a DM or group channel in Adapt.
This is the base class for all types of private channels, and should not be used directly.
- type#
The type of the channel. Can be either
dm
orgroup
.ChannelType.is_dm
for this value will always beTrue
.- Type:
- property created_at#
The time the object was created.
- property id#
The ID of the object.
- property recipients#
The recipients of the channel, including yourself.
This is a shortcut for calling
Connection.get_user()
with each ID inrecipient_ids
. Users that are not cached will be excluded from the list.- Type:
list`[:class:
.User`]
Enums#
Standard Enums#
- class adapt.ModelType#
This is an enum.
Enumeration of model types.
- channel#
The model is a
Channel
.
- attachment#
The model is an
Attachment
.
- role#
The model is a
Role
.
- internal#
The model is an internal model.
- unknown#
The model type is unknown.
- class adapt.Status#
This is an enum.
The status of a user’s presence.
- online#
The user is online.
- idle#
The user is idle.
- dnd#
The user is has enabled Do Not Disturb.
- offline#
The user is offline.
- class adapt.RelationshipType#
This is an enum.
The type of a relationship.
- friend#
The user is your friend.
- outgoing_request#
You have sent a friend request to the user.
- incoming_request#
You have received a friend request from the user.
- blocked#
You have blocked the user.
- class adapt.ChannelType#
This is an enum.
The type of a channel.
- text#
The channel is a text channel.
- announcement#
The channel is an announcement channel.
- voice#
The channel is a voice channel.
- category#
The channel is a category channel.
- dm#
The channel is a DM channel.
- group#
The channel is a group DM channel.
Bitflag Enums#
- class adapt.Bitflags(value=..., **flags)#
The base class that all bitflag classes inherit from. This class is not meant to be used directly.
Bitflags are a way to represent multiple boolean values in a single integer. This class provides a way to easily read and manipulate these boolean values.
- Parameters:
Examples
We will use the
Permissions
class as an example.Create a new permissions instance with specific flags:
permissions = Permissions(view_channel=True, send_messages=True)
Create a new permissions instance with a specific value:
permissions = Permissions(5) # Equivalent to Permissions(view_channel=True, send_messages=True)
Read the value of a specific flag:
permissions.view_channel # True permissions.add_reactions # False
Set the value of a specific flag:
permissions.view_channel = False permissions.view_channel # False # Using the `del` keyword will set the flag to False del permissions.view_channel # Equivalent to permissions.view_channel = False
Create a new permissions instance from another:
permissions = Permissions(view_channel=True, send_messages=True) modified = permissions.copy_with(send_messages=False) permissions.send_messages # True modified.send_messages # False
Helper methods are also provided to make it easier to work with bitflags:
no_permissions = Permissions.none() # Equivalent to Permissions(0) all_permissions = Permissions.all() # Enable all flags default_permissions = Permissions.default() # Use the default value
Turn a permissions instance into a dictionary:
permissions = Permissions(view_channel=True, send_messages=True) dict(permissions) # {'view_channel': True, 'send_messages': True, 'add_reactions': False, ...} # Turn it into a list of enabled flags [name for name, value in permissions if value] # ['view_channel', 'send_messages']
- classmethod all()#
Creates a new instance with all flags set to
True
.- Returns:
The new instance.
- Return type:
- copy_with(**overrides)#
Returns a copy of this instance with the given flag overrides applied.
- classmethod default()#
Creates a new instance with the default flags.
- Returns:
The new instance.
- Return type:
- class adapt.UserFlags(value=..., **flags)#
This is represented using
Bitflags
.Represents special properties about a user.
- class adapt.PrivacyConfiguration(value=..., **flags)#
This is represented using
Bitflags
.Represents the privacy configuration of a user.
- class adapt.GuildFlags(value=..., **flags)#
This is represented using
Bitflags
.Represents extra properties and features about a guild.
- class adapt.MessageFlags(value=..., **flags)#
This is represented using
Bitflags
.Represents extra properties and features about a message.
- class adapt.RoleFlags(value=..., **flags)#
This is represented using
Bitflags
.Represents extra properties and features about a role.
- class adapt.Permissions(value=..., **flags)#
This is represented using
Bitflags
.Represents a set of permissions.
- view_channel#
People with this permission can view channels and receive events from them.
- Type:
- view_message_history#
People with this permission can view the message history of channels. The view_channel permission is not necessarily required to view the message history, however it means you cannot receive or send new messages in the channel.
- Type:
- send_messages#
People with this permission can send messages in channels. The view_channel permission is required to send messages.
- Type:
- manage_messages#
People with this permission can manage messages sent by other people. This allows for the following:
Deleting messages sent by others
Deleting attachments or embeds sent by others
Removing reactions of others
Unpublishing messages sent by others (Announcement channels only)
Note that anyone can still delete their own messages.
- Type:
- send_embeds#
People with this permission can send rich embeds or have embed links automatically appear.
- Type:
- add_reactions#
People with this permission can add new reactions to messages. Note that users without this permission can still react to already existing reactions.
- Type:
- publish_messages#
People with this permission can publish messages to the announcement feed.
- Type:
- manage_starboard#
People with this permission can delete starboard posts, or disable the starboard completely.
- Type:
- manage_roles#
People with this permission can manage the guild’s roles. They will be able to change the permissions of any roles below their top role, and they will be forbidden to grant or deny any permissions they do not have themselves. They can also assign and remove any roles to other members, as long as the target role is below their top role.
- Type:
- manage_invites#
People with this permission can revoke or pause invites of any channel in the guild. This does not take into account the create_invites permission, meaning they can revoke invites even if they cannot create them.
- Type:
- timeout_members#
People with this permission can timeout and untimeout members that are lower than them in role hierarchy.
- Type:
- kick_members#
People with this permission can kick members that are lower than them in role hierarchy.
- Type:
- ban_members#
People with this permission can ban and unban members that are lower than them in role hierarchy.
- Type:
- bulk_delete_messages#
People with this permission can delete or purge messages in bulk. Unlike Discord, the API allows for up to any number of messages to be deleted at a time.
- Type:
- view_audit_log#
People with this permission can view an audit log of past moderation or other privileged actions.
- Type:
- privileged_mentions#
People with this permission can mention large groups of people. This means mentioning everyone under a non-mentionable role or mentioning everyone.
- Type:
Utility Functions#
- adapt.util.extract_user_id_from_token(token, /)#
Extracts the user ID associated with the given authentication token.
- Parameters:
token (
str
) – The token to parse.- Returns:
The snowflake ID of the associated user.
- Return type:
- Raises:
ValueError – Received a malformed token.
- adapt.util.find(iterable, predicate)#
Finds the first element in an iterable that satisfies the given predicate.
- Parameters:
iterable (Iterable[T]) – The iterable to search through.
predicate ((item: T) ->
bool
) – The predicate to use to find the element.
- Returns:
The first element that satisfies the predicate, or
None
if no such element is found.- Return type:
T | None
- adapt.util.snowflake_model_type(snowflake, /)#
Extracts the model type of the given Adapt snowflake.
- Parameters:
snowflake (
int
) – The snowflake to extract the model type from.- Returns:
The model type associated with the snowflake.
- Return type:
ModelType