Client's parameters, this includes bot's token & rest options.
Client's cache.
Default event names to TouchGuild event names.
Client's params, including bot's token & rest options.
Optional REST?: booleanOptional RESTOptions?: RESTOptionsREST methods.
Optional userClient's user.
Websocket Manager.
Static Readonly captureStatic captureSets or gets the default captureRejection value for all emitters.
Static defaultStatic Readonly errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular
'error' listeners are called.
Installing a listener using this symbol does not change the behavior once an
'error' event is emitted, therefore the process will still crash if no
regular 'error' listener is installed.
Bot's token.
Rest ...args: ClientEvents[K]Create an event into a "Calendar" channel.
ID of a "Calendar" channel.
Event options.
Create a channel in a specified guild.
ID of a guild.
Name of the new channel.
Type of the new channel. (e.g: chat)
Optional options: CreateChannelOptionsNew channel's additional options.
Create a doc in a "Docs" channel.
ID pf a "Docs" channel.
Doc's options.
Add a comment to a forum thread.
ID of a "Forums" channel.
ID of a forum thread.
Comment's options.
Create a forum thread in a specified forum channel.
ID of a "Forums" channel.
Thread's options including title & content.
Create a new item in a list channel.
ID of a "Lists" channel.
String content of the new item.
Optional note: { Add a note to the new item.
The note of the list item
Send a message in a specified channel.
ID of the channel.
Message options
Add a reaction to a specified object.
ID of a channel that supports reaction.
Type of the selected channel. (e.g: "ChannelMessage")
ID of the object you'd like to add the reaction to. (e.g: a message id)
ID of the reaction.
Edit an event from a "Calendar" channel.
ID of a "Calendar" channel.
ID of a calendar event.
Edit options.
Add/Edit a RSVP in a calendar event.
ID of a "Calendar" channel.
ID of a calendar event.
ID of a member.
Edit options.
Edit a channel.
ID of the channel you'd like to edit.
Channel edit options.
Edit a doc from a "Docs" channel.
ID of a "Docs" channel.
ID of a doc.
Edit options.
Edit a forum thread's comment.
ID of a "Forums" channel.
ID of a forum thread.
ID of a thread comment.
Optional options: EditForumCommentOptionsEdit options.
Edit a forum thread from a specified forum channel.
ID of a "Forums" channel.
ID of a forum thread.
Edit options.
Edit an item from a list channel.
ID of a "Lists" channel.
ID of a list item.
New item's content.
Optional note: { Add a note to the item.
The note of the list item
Edit a specific message coming from a specified channel.
The ID of the channel.
The ID of the message you'd like to edit.
object containing new message's options.
Update a webhook
ID of a guild.
ID of an existent webhook.
Edit options.
Rest ...args: ClientEvents[K]Rest ...args: ClientEvents[K]Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
const EventEmitter = require('events');
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
v6.0.0
This method is used to get a specific calendar event.
Note: this method requires a "Calendar" channel.
ID of a Calendar channel.
ID of a Calendar event.
This method is used to get a list of CalendarEvent
ID of a "Calendar" channel.
Optional filter: GetCalendarEventsFilterObject to filter the output.
This method is used to get a specific CalendarEventRSVP.
Note: this method requires a Calendar channel.
ID of a Calendar channel
ID of a Calendar Event
ID of a Guild Member
This method is used to get a list of CalendarEventRSVP.
ID of a "Calendar" channel.
ID of a calendar event.
This method is used to get a list of Message
ID of a "Chat" channel.
Optional filter: GetChannelMessagesFilterObject to filter the output.
This method is used to get a list of "Channel" Doc.
ID of a "Docs" channel.
Optional filter: GetDocsFilterObject to filter the output.
This method is used to get a specific forum thread comment.
ID of a "Forums" channel.
ID of a Forum thread.
ID of a Forum thread comment.
This method is used to get a list of ForumThreadComment.
ID of a "Forums" channel.
ID of a Forum Thread.
This method is used to get a specific forum thread.
Note: This method requires a "Forum" channel.
ID of a speific Forum channel.
ID of the specific Forum Thread.
This method is used to get a list of ForumThread.
ID of a "Forum" channel.
Optional filter: GetForumThreadsFilterObject to filter the output.
Returns the current max listener value for the EventEmitter which is either
set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.
v1.0.0
Rest ...args: ClientEvents[K]Rest ...args: ClientEvents[K]Rest ...args: ClientEvents[K]Rest ...args: ClientEvents[K]Rest ...args: ClientEvents[K]Optional event: keyof ClientEventsRest ...args: ClientEvents[K]Remove a reaction from a specified message.
ID of a channel that supports reaction.
Type of the selected channel. (e.g: "ChannelMessage")
ID of the object you'd like to add the reaction to. (e.g: a message id)
ID of the reaction.
By default EventEmitters will print a warning if more than 10 listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners() method allows the limit to be
modified for this specific EventEmitter instance. The value can be set toInfinity (or 0) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter, so that calls can be chained.
v0.3.5
Static getReturns a copy of the array of listeners for the event named eventName.
For EventEmitters this behaves exactly the same as calling .listeners on
the emitter.
For EventTargets this is the only way to get the event listeners for the
event target. This is useful for debugging and diagnostic purposes.
const { getEventListeners, EventEmitter } = require('events');
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
getEventListeners(ee, 'foo'); // [listener]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
getEventListeners(et, 'foo'); // [listener]
}
v15.2.0, v14.17.0
Static listenerA class method that returns the number of listeners for the given eventNameregistered on the given emitter.
const { EventEmitter, listenerCount } = require('events');
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
v0.9.12
Since v3.2.0 - Use listenerCount instead.
The emitter to query
The event name
Static onconst { on, EventEmitter } = require('events');
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
Returns an AsyncIterator that iterates eventName events. It will throw
if the EventEmitter emits 'error'. It removes all listeners when
exiting the loop. The value returned by each iteration is an array
composed of the emitted event arguments.
An AbortSignal can be used to cancel waiting on events:
const { on, EventEmitter } = require('events');
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
v13.6.0, v12.16.0
that iterates eventName events emitted by the emitter
The name of the event being listened for
Optional options: StaticEventEmitterOptionsStatic onceCreates a Promise that is fulfilled when the EventEmitter emits the given
event or that is rejected if the EventEmitter emits 'error' while waiting.
The Promise will resolve with an array of all the arguments emitted to the
given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error' event
semantics and does not listen to the 'error' event.
const { once, EventEmitter } = require('events');
async function run() {
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.log('error happened', err);
}
}
run();
The special handling of the 'error' event is only used when events.once()is used to wait for another event. If events.once() is used to wait for the
'error' event itself, then it is treated as any other kind of event without
special handling:
const { EventEmitter, once } = require('events');
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.log('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
An AbortSignal can be used to cancel waiting for the event:
const { EventEmitter, once } = require('events');
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
v11.13.0, v10.16.0
Optional options: StaticEventEmitterOptionsOptional options: StaticEventEmitterOptionsStatic setconst {
setMaxListeners,
EventEmitter
} = require('events');
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
v15.4.0
Optional n: numberA non-negative number. The maximum number of listeners per EventTarget event.
Rest ...eventTargets: (EventEmitter | _DOMEventTarget)[]
Represents the bot's client.