slidcord.client

Attributes

Classes

Discord

Represents a client connection that connects to Discord.

Functions

captcha_handler(captcha_required, client)

Module Contents

slidcord.client.MessageableChannel[source]
slidcord.client.Author[source]
async slidcord.client.captcha_handler(captcha_required, client)[source]
Parameters:
  • captcha_required (discord.CaptchaRequired)

  • client (Discord)

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.

Added in version 2.0.

A number of options can be passed to the Client.

Changed in version 2.1: Removed the http_trace parameter.

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.

Added 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.

Added 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.

Added 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.

Added 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.

Added in version 2.0.

afk: bool

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

Added in version 2.1.

allowed_mentions: Optional[AllowedMentions]

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

Added 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.

Added 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.

Added 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).

Added in version 2.0.

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

A function that solves captcha challenges.

Added 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.

Added in version 2.0.

preferred_rtc_regions: List[str]

A list of preferred RTC regions to connect to. This overrides Discord’s suggested list.

Added in version 2.1.

canary: bool

Whether to forcefully route all requests to the canary API. This is useful for testing new features.

Note that this doesn’t use the canary release channel.

Added in version 2.1.

apm_tracing: bool

Whether to enable Application Performance Monitoring (APM) tracing.

This will print debug logs for every HTTP request made by the library with an APM trace URL that Discord employees can view.

Added in version 2.1.

Attributes

ws

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

session[source]
log[source]
ignore_next_msg_event[source]
__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:
  • before (discord.Message)

  • after (discord.Message)

async on_message_delete(m)[source]
Parameters:

m (discord.Message)

async on_reaction_add(reaction, user)[source]
Parameters:
  • reaction (discord.Reaction)

  • user (Author)

async on_reaction_remove(reaction, user)[source]
Parameters:
  • reaction (discord.Reaction)

  • user (Author)

async update_reactions(reaction, user)[source]
Parameters:
  • reaction (discord.Reaction)

  • user (Author)

async on_presence_update(_before, after)[source]
Parameters:
  • _before (Union[discord.Member, discord.Relationship])

  • after (Union[discord.Member, discord.Relationship])

async on_friend_presence_update(friend)[source]
Parameters:

friend (discord.Relationship)

async on_guild_presence_update(member)[source]
Parameters:

member (discord.Member)

async on_relationship_add(relationship)[source]
Parameters:

relationship (discord.Relationship)

async on_relationship_update(_before, after)[source]
Parameters:
  • _before (discord.Relationship)

  • after (discord.Relationship)

async on_relationship_remove(relationship)[source]
Parameters:

relationship (discord.Relationship)

async _get_private_muc(channel)[source]
Parameters:

channel (discord.abc.PrivateChannel)

Return type:

Optional[slidcord.group.MUC]

async on_private_channel_create(channel)[source]
Parameters:

channel (discord.abc.PrivateChannel)

async on_private_channel_update(channel)[source]
Parameters:

channel (discord.abc.PrivateChannel)

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)