Client¶
The gateway client
- class cordy.client.Client(token: StrOrToken, *, intents: Intents | None = None, sharder_cls: type[BaseSharder] = <class 'cordy.gateway.Sharder'>, num_shards: int | None = None, shard_ids: Sequence[int] | None = None)[source]¶
The discord API Gateway client.
- intents¶
The gateway intents used by the client
- Type
Intent
- emitter¶
The client event emitter. You don’t need to interact with this if you do not want custom events
- Type
Emitter
- publisher¶
The event publisher.
- Type
Publisher
- shard_ids¶
The shard ids to launch. If
Nonethen sharder automatically shards the client- Type
set, (set[int] | None)
- num_shard¶
The total number of shards the client has, this number includes shards which are not under this client.
- Type
int, (int | None)
- sharder¶
The gateway sharder for the client.
- Type
BaseSharder, (BaseSharder[Shard])
- Parameters
token (
str,Token, (str | Token)) – The token for the gateway. Is a string is provided then a bot token is built. This is a required argument. All following arguments are keyword only.intents (
Intent) – This is an optional parameter. The gateway intents used by the client. If None, then value returned bydefault()is used. by default None.sharder_cls (type[
BaseSharder]) – The sharder type to use. Must subclass theBaseSharderprotocol. IfNonethenSharderis used. By defaultNonenum_shards (
int) – The total number of shards. IfNoneClient.sharderprovided value will be used. By defaultNoneshard_ids (Sequence[
int]) – A sequence of shard ids that this client should launch. If notNonethennum_shardsparameter must be provided. IfNonethen shards are generated fromnum_shardsorClient.sharderprovided value will be used.
- listen(name: str | None = None) Callable[[CoroFn], CoroFn][source]¶
This method is used as a decorator. Add the decorated function as a listener for the specified event
- add_listener(func: CoroFn, name: str | None = None) None[source]¶
Add a listener for the given event.
- remove_listener(func: CoroFn, name: str | None = None) None[source]¶
Remove a registered listener. If the listener or event is not found, then does nothing.
- async wait_for(name: str, timeout: int | None = None, check: CheckFn | None = None) tuple[Any, ...][source]¶
Wait for an event to occur.
- Parameters
name (
str) – The name of the event to wait for.timeout (
int) – The time to wait for the event to occur, ifNonethen wait indefinetly, by defaultNonecheck (Callable[…,
bool]) – The check function, a subroutine returning a boolean, the provided arguments are the same as the returnedtuple. If the check function returnsTruethen the same data that was given to the check function will be returned, or else continue waiting for the event. IfNonethen return the first event data, by defaultNone
- Returns
The data associated with the event. This is the same as the arguments received by listeners for the event.
- Return type
tuple[Any, …]
- async setup() None[source]¶
Initialise client with the current running event loop. This is implicity called when the gateway is launched, otherwise this needs to be called explicitly with a running loop.