slidcord.client#

Module Contents#

Classes#

Discord

Represents a client connection that connects to Discord.

Functions#

captcha_handler(captcha_required, client)

Attributes#

slidcord.client.MessageableChannel[source]#
slidcord.client.Author[source]#
async slidcord.client.captcha_handler(captcha_required, client)[source]#
Parameters:
Return type:

str

class slidcord.client.Discord(session)[source]#

Bases: discord.Client

Represents a client connection that connects to Discord. This class is used to interact with the Discord WebSocket and API.

async with x

Asynchronously initialises the client and automatically cleans up.

New in version 2.0.

A number of options can be passed to the Client.

Parameters#

max_messages: Optional[int]

The maximum number of messages to store in the internal message cache. This defaults to 1000. Passing in None disables the message cache.

Changed in version 1.3: Allow disabling the message cache and change the default size to 1000.

proxy: Optional[str]

Proxy URL.

proxy_auth: Optional[aiohttp.BasicAuth]

An object that represents proxy HTTP Basic Authorization.

member_cache_flags: MemberCacheFlags

Allows for finer control over how the library caches members. If not given, defaults to cache as much as possible.

New in version 1.5.

chunk_guilds_at_startup: bool

Indicates if on_ready() should be delayed to chunk all guilds at start-up if necessary. This operation is incredibly slow for large amounts of guilds. The default is True.

New in version 1.5.

guild_subscriptions: bool

Whether to subscribe to all guilds at startup. This is required to receive member events and populate the thread cache.

For larger servers, this is required to receive nearly all events.

See guild_subscriptions for more information.

New in version 2.1.

Warning

If this is set to False, the following consequences will occur:

  • Large guilds (over 75,000 members) will not dispatch any non-stateful events (e.g. on_message(), on_reaction_add(), on_typing(), etc.)

  • threads will only contain threads the client has joined.

  • Guilds will not be chunkable and member events (e.g. on_member_update()) will not be dispatched.
    • Most on_user_update() occurences will not be dispatched.

    • The member (members) and user (users) cache will be largely incomplete.

    • Essentially, only the client user, friends/implicit relationships, voice members, and other subscribed-to users will be cached and dispatched.

This is useful if you want to control subscriptions manually (see Guild.subscribe()) to save bandwidth and memory. Disabling this is not recommended for most use cases.

request_guilds: bool

See guild_subscriptions.

New in version 2.0.

Deprecated since version 2.1: This is deprecated and will be removed in a future version. Use guild_subscriptions instead.

status: Optional[Status]

A status to start your presence with upon logging on to Discord.

activity: Optional[BaseActivity]

An activity to start your presence with upon logging on to Discord.

activities: List[BaseActivity]

A list of activities to start your presence with upon logging on to Discord. Cannot be sent with activity.

New in version 2.0.

afk: bool

Whether to start your session as AFK. Defaults to False.

New in version 2.1.

allowed_mentions: Optional[AllowedMentions]

Control how the client handles mentions by default on every message sent.

New in version 1.4.

heartbeat_timeout: float

The maximum numbers of seconds before timing out and restarting the WebSocket in the case of not receiving a HEARTBEAT_ACK. Useful if processing the initial packets take too long to the point of disconnecting you. The default timeout is 60 seconds.

assume_unsync_clock: bool

Whether to assume the system clock is unsynced. This applies to the ratelimit handling code. If this is set to True, the default, then the library uses the time to reset a rate limit bucket given by Discord. If this is False then your system clock is used to calculate how long to sleep for. If this is set to False it is recommended to sync your system clock to Google’s NTP server.

New in version 1.3.

enable_debug_events: bool

Whether to enable events that are useful only for debugging gateway related information.

Right now this involves on_socket_raw_receive() and on_socket_raw_send(). If this is False then those events will not be dispatched (due to performance considerations). To enable these events, this must be set to True. Defaults to False.

New in version 2.0.

sync_presence: bool

Whether to keep presences up-to-date across clients. The default behavior is True (what the client does).

New in version 2.0.

http_trace: aiohttp.TraceConfig

The trace configuration to use for tracking HTTP requests the library does using aiohttp. This allows you to check requests the library is using. For more information, check the aiohttp documentation.

New in version 2.0.

captcha_handler: Optional[Callable[[CaptchaRequired, Client], Awaitable[str]]

A function that solves captcha challenges.

New in version 2.0.

Changed in version 2.1: Now accepts a coroutine instead of a CaptchaHandler.

max_ratelimit_timeout: Optional[float]

The maximum number of seconds to wait when a non-global rate limit is encountered. If a request requires sleeping for more than the seconds passed in, then RateLimited will be raised. By default, there is no timeout limit. In order to prevent misuse and unnecessary bans, the minimum value this can be set to is 30.0 seconds.

New in version 2.0.

Attributes#

ws

The websocket gateway the client is currently connected to. Could be None.

__ignore(mid)[source]#
Parameters:

mid (int) –

async on_message(message)[source]#
Parameters:

message (discord.Message) –

async on_typing(channel, user, _when)[source]#
Parameters:
  • channel (MessageableChannel) –

  • user (Author) –

async on_message_edit(before, after)[source]#
Parameters:
async on_message_delete(m)[source]#
Parameters:

m (discord.Message) –

async on_reaction_add(reaction, user)[source]#
Parameters:
async on_reaction_remove(reaction, user)[source]#
Parameters:
async update_reactions(reaction, user)[source]#
Parameters:
async on_presence_update(_before, after)[source]#
Parameters:
async on_friend_presence_update(friend)[source]#
Parameters:

friend (discord.Relationship) –

async on_guild_presence_update(member)[source]#
Parameters:

member (discord.Member) –

async get_contact(user)[source]#
Parameters:

user (Union[discord.User, discord.Member]) –

async get_sender_by_message(message)[source]#
Parameters:

message (discord.Message) –

async get_sender(author, channel)[source]#
Parameters:
  • author (Author) –

  • channel (MessageableChannel) –

Return type:

Optional[Union[slidcord.contact.Contact, slidcord.group.Participant]]

Parameters:

session (slidcord.session.Session) –