Client
The main class that is used to use Carbon
The main class that is used to use Carbon is the Client class. Everything all connects to this one class, and it is the main instance for your bot.
Creating a Client
const client = new Client({
baseUrl: " ... ",
deploySecret: " ... ",
clientId: " ... ",
publicKey: " ... ",
token: " ... ",
}, [new PingCommand()])Here we have created a client with the following options:
baseUrl: The relative base URL of your appdeploySecret: The deploy secret of your bot, used as a password for deploying commands and other sensitive mattersclientId: The Discord client ID of your botpublicKey: The Discord public key of your bottoken: The Discord token of your bot
And we have also provided it with a list of commands, which in this case is just the PingCommand we created earlier.
Event Queue Options
The client can be configured with an event queue to control how gateway events are processed.
const client = new Client({
baseUrl: " ... ",
deploySecret: " ... ",
clientId: " ... ",
publicKey: " ... ",
token: " ... ",
eventQueue: {
maxQueueSize: 10000,
maxConcurrency: 50,
listenerTimeout: 30000,
listenerConcurrency: 10,
yieldIntervalMs: 0,
logSlowListeners: true,
slowListenerThreshold: 1000
}
}, [new PingCommand()])maxQueueSize: Maximum number of events that can be queued before backpressure is appliedmaxConcurrency: Maximum number of concurrent event processing operationslistenerTimeout: Maximum time in ms a single listener can take before timing outlistenerConcurrency: Maximum number of listeners processed at the same time per eventyieldIntervalMs: Yield to the event loop after this many ms of listener worklogSlowListeners: Whether to log slow listenersslowListenerThreshold: Threshold in ms for logging slow listeners
Guidance:
- Use lower
listenerConcurrency(1-5) for CPU-heavy or sync I/O handlers, higher for mostly async work. - Set
yieldIntervalMsto 10-50ms for long-running handlers to reduce event loop starvation, or keep 0 for maximum throughput.
Edit on GitHub
Last updated on
