Client
TheClient class represents a client connection that connects to Discord. This class is used to interact with the Discord WebSocket and API.
Constructor
Client
The maximum number of messages to store in the internal message cache. Pass
None to disable the message cache.The event loop to use for asynchronous operations. Defaults to
asyncio.get_event_loop().The connector to use for connection pooling.
Proxy URL.
An object that represents proxy HTTP Basic Authorization.
Integer starting at
0 and less than shard_count.The total number of shards.
The client’s application ID.
The intents that you want to enable for the session. This is a way of disabling and enabling certain gateway events from triggering and being sent.
Allows for finer control over how the library caches members. If not given, defaults to cache as much as possible with the currently selected intents.
Indicates if
on_ready should be delayed to chunk all guilds at start-up if necessary. The default is True if Intents.members is True.A status to start your presence with upon logging on to Discord.
An activity to start your presence with upon logging on to Discord.
Control how the client handles mentions by default on every message sent.
The maximum numbers of seconds before timing out and restarting the WebSocket in the case of not receiving a HEARTBEAT_ACK.
The maximum number of seconds to wait for the GUILD_CREATE stream to end before preparing the member cache and firing READY.
Whether to assume the system clock is unsynced. This applies to the ratelimit handling code.
Whether to enable events that are useful only for debugging gateway related information (
on_socket_raw_receive and on_socket_raw_send).Whether to automatically fetch and cache the application’s emojis on startup and when fetching.
Whether to automatically fetch and cache the default soundboard sounds on startup.
Attributes
The WebSocket gateway the client is currently connected to. Could be
None.The event loop that the client uses for asynchronous operations.
Represents the connected client.
None if not logged in.The guilds that the connected client is a member of.
The emojis that the connected client has. Only includes application emojis if
cache_app_emojis is True.The stickers that the connected client has.
Read-only list of messages the connected client has cached.
The private channels that the connected client is participating on. Returns only up to 128 most recent private channels.
Represents a list of voice connections.
The client’s application ID.
The client’s application flags.
Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. Returns
nan if no websocket is present, or inf if no heartbeat has been received yet.Returns a list of all the users the bot can see.
Connection Methods
login
login
login
The authentication token. Do not prefix this token with anything as the library will do it for you.
TypeError- The token was in invalid type.LoginFailure- The wrong credentials are passed.HTTPException- An unknown HTTP related error occurred.
connect
connect
connect
If we should attempt reconnecting, either due to internet failure or a specific failure on Discord’s part.
GatewayNotFound- The gateway to connect to Discord is not found.ConnectionClosed- The WebSocket connection has been terminated.
close
close
start
start
run
run
run
clear
clear
clear
is_closed() and is_ready() both return False along with the bot’s internal cache cleared.Status Methods
is_closed
is_closed
is_closed
bool - Whether the connection is closed.is_ready
is_ready
is_ready
bool - Whether the cache is ready.is_ws_ratelimited
is_ws_ratelimited
is_ws_ratelimited
bool - Whether the WebSocket is rate limited.Presence Methods
change_presence
change_presence
Event Registration
event
event
event
This replaces any default handlers. Use
listen() for adding additional handlers instead of event() unless default method replacement is intended.listen
listen
listen
The name of the event to listen for. Must start with
on_.Whether the listener should only be called once.
add_listener
add_listener
remove_listener
remove_listener
wait_for
wait_for
wait_for
The event name, similar to the event reference, but without the
on_ prefix, to wait for.A predicate to check what to wait for. The arguments must meet the parameters of the event being waited for.
The number of seconds to wait before timing out and raising
asyncio.TimeoutError.wait_until_ready
wait_until_ready
Cache Getters
get_channel
get_channel
get_guild
get_guild
get_user
get_user
get_emoji
get_emoji
get_sticker
get_sticker
get_all_channels
get_all_channels
get_all_channels
GuildChannel the client can ‘access’.Yields: GuildChannel - A channel the client can ‘access’.get_all_members
get_all_members
get_all_members
Member the client can see.Yields: Member - A member the client can see.API Fetch Methods
fetch_guild
fetch_guild
fetch_user
fetch_user
fetch_channel
fetch_channel
fetch_guilds
fetch_guilds
fetch_guilds
AsyncIterator that enables receiving your guilds.The number of guilds to retrieve. If
None, retrieves every guild.Retrieves guilds before this date or object.
Retrieve guilds after this date or object.
Whether to include member count information in guilds.
fetch_invite
fetch_invite
fetch_invite
Invite from a discord.gg URL or ID.The Discord invite ID or URL (must be a discord.gg URL).
Whether to include count information in the invite.
Whether to include the expiration date of the invite.
The ID of the scheduled event to be associated with the event.
application_info
application_info
application_info
Error Handlers
on_error
on_error
on_error
sys.stderr however it could be overridden to have a different implementation.The name of the event that raised the exception.
The positional arguments for the event.
The keyword arguments for the event.
