slidcord.client¶
Attributes¶
Classes¶
Represents a client connection that connects to Discord. |
Functions¶
|
Module Contents¶
- 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 inNone
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 isTrue
.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.
- Guilds will not be chunkable and member events (e.g.
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 isFalse
then your system clock is used to calculate how long to sleep for. If this is set toFalse
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()
andon_socket_raw_send()
. If this isFalse
then those events will not be dispatched (due to performance considerations). To enable these events, this must be set toTrue
. Defaults toFalse
.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 is30.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
.
- 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_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_relationship_update(_before, after)[source]¶
- Parameters:
_before (discord.Relationship)
after (discord.Relationship)
- async _get_private_muc(channel)[source]¶
- Parameters:
channel (discord.abc.PrivateChannel)
- Return type:
Optional[slidcord.group.MUC]
- 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)