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
None
then 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 theBaseSharder
protocol. IfNone
thenSharder
is used. By defaultNone
num_shards (
int
) – The total number of shards. IfNone
Client.sharder
provided value will be used. By defaultNone
shard_ids (Sequence[
int
]) – A sequence of shard ids that this client should launch. If notNone
thennum_shards
parameter must be provided. IfNone
then shards are generated fromnum_shards
orClient.sharder
provided 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, ifNone
then wait indefinetly, by defaultNone
check (Callable[…,
bool
]) – The check function, a subroutine returning a boolean, the provided arguments are the same as the returnedtuple
. If the check function returnsTrue
then the same data that was given to the check function will be returned, or else continue waiting for the event. IfNone
then 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.