Skip to content

Client API

Note

The following classes come from the scurrypy.client module.


Client

Main entry point for Discord bots. Ties together the moving parts: gateway, HTTP and event dispatching.

Parameters:

  • token (str) –

    the bot's token

  • intents (int, default: DEFAULT ) –

    gateway intents. Defaults to Intents.DEFAULT.

  • shard_count (int, default: 0 ) –

    number of shards to spawn. Defaults to 0 or recommended shard count.

token: str = token instance-attribute

Bot's token.

intents: int = intents instance-attribute

Bot intents for listening to events.

shard_count = shard_count instance-attribute

http: HTTPClient = self._http instance-attribute

Public HTTP session (ref to _http) for requests.

shards: list[GatewayClient] = [] instance-attribute

Shards as a list of gateways.

events: dict[str:(list[callable])] = {} instance-attribute

Events for the client to listen to.

startup_hooks: list[callable] = [] instance-attribute

Handlers to call once before the bot starts.

shutdown_hooks: list[callable] = [] instance-attribute

Handlers to call once after the bot shuts down.

add_event_listener

Helper function to register listener functions.

Parameters:

  • event (str) –

    name of the event to listen

  • handler (callable) –

    listener function

add_startup_hook

Helper function to register startup functions. Runs once on startup BEFORE READY event.

Parameters:

  • handler (callable) –

    startup function

add_shutdown_hook

Helper function to register shutdown functions. Runs once on shutdown.

Parameters:

  • handler (callable) –

    shutdown function

application

Creates an interactable application resource.

Parameters:

  • application_id (int) –

    ID of target application

Returns:

bot_emoji

Creates an interactable bot emoji resource.

Parameters:

  • application_id (int) –

    ID of target application

Returns:

  • BotEmojis

    the BotEmoji resource

guild_emoji

Creates an interactable emoji resource.

Parameters:

  • guild_id (int) –

    guild ID of target emojis

Returns:

guild

Creates an interactable guild resource.

Parameters:

  • guild_id (int) –

    ID of target guild

  • context (Any, default: None ) –

    associated data

Returns:

  • Guild

    the Guild resource

channel

Creates an interactable guild channel resource.

Parameters:

  • channel_id (int) –

    ID of target channel

  • context (Any, default: None ) –

    associated data

Returns:

  • GuildChannel

    the GuildChannel resource

invite

Creates an interactable invite resource.

Parameters:

  • code (str) –

    unique invite code

  • context (_type_, default: None ) –

    associated data

global_command

Creates an interactable command resource.

Parameters:

  • application_id (int) –

    bot's user ID

  • context (Any, default: None ) –

    associated data

Returns:

guild_command

Creates an interactable command resource.

Parameters:

  • application_id (int) –

    bot's user ID

  • guild_id (int, default: None ) –

    ID of guild if command is in guild scope

  • context (Any, default: None ) –

    associated data

Returns:

message

Creates an interactable message resource.

Parameters:

  • message_id (int) –

    ID of target message

  • channel_id (int) –

    channel ID of target message

  • context (Any, default: None ) –

    associated data

Returns:

interaction

Creates an interactable interaction resource.

Parameters:

  • id (int) –

    ID of the interaction

  • token (str) –

    interaction token

  • context (Any, default: None ) –

    associated data

Returns:

sticker

Creates an interactable sticker resource

Parameters:

  • context (Any, default: None ) –

    associated data

Returns:

  • Sticker

    the Sticker resource

user

Creates an interactable user resource.

Parameters:

  • context (Any, default: None ) –

    associated data

Returns:

  • User

    the User resource

listen_shard async

Consume a GatewayClient's event queue.

Parameters:

start async

Starts the HTTP/Websocket client, run startup logic, and registers commands.

run

User-facing entry point for starting the client.