Client's parameters, this includes bot's token & rest options.
Cached guilds.
Client's params, including bot's token & rest options.
REST methods.
Optional
userClient's user.
Cached users.
Utils
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]Bulk create/update calendar rsvps.
ID of the Calendar channel.
ID of a calendar event.
List of multiple member ids.
Update options.
Bulk delete every reaction from a target.
ID of a channel.
Type of channel.
Target to remove reactions from it.
Optional
filter: DELETEMessageReactionQueryCreate a new announcement within an announcement channel.
ID of the Announcement channel.
Announcement creation options.
Create a comment inside an announcement.
ID of the Announcement channel.
ID of the announcement to create the comment in.
Comment creation options.
Ban a guild member.
ID of the guild the member is in.
ID of the member to ban.
Optional
reason: stringThe reason of the ban.
Create a comment inside a calendar event.
The ID of a "Calendar" channel.
The ID of a calendar event.
Comment options, includes content, and more.
Create an event into a "Calendar" channel.
ID of a "Calendar" channel.
Event options.
Optional
createSeries: { (optional) Create a series. (event's repetition)
Optional
endThe ISO 8601 timestamp that the event ends at. Used to control the end date of the event repeat (only used when type is custom; if used with endsAfterOccurrences, the earliest resultant date of the two will be used)
Optional
endsUsed to control the end date of the event repeat (only used when type is custom; if used with endDate, the earliest resultant date of the two will be used) (max 24)
Optional
every?: { Apply further clarification to your events. This must have type set to custom
How often between your interval the event should repeat. For example, 1 would be every interval, 2 would be every second occurrence of the interval
Coupled with count, this indicates the time range you are repeating your event over
Optional
on?: ("sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday")[]Used to control the day of the week that the event should repeat on (only used when type is custom and when every.interval is week) (min items 1)
How often you want your event to repeat (important note: this will repeat for the next 180 days unless custom is defined) (default once)
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.
Create a comment in a doc.
ID of the docs channel.
ID of the doc.
Create 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 guild group.
The ID of the guild to create a group in.
Create options
Create a guild role.
ID of the server you want to create the role in.
Create options
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 target.
ID of a channel that supports reaction.
Type of the selected channel. (e.g: "ChannelMessage")
ID of the target you'd like to add the reaction to. (e.g: a message id)
ID of the reaction.
Add a reaction to a target from a subcategory (e.g: a comment from Forum Thread)
ID of a channel that supports reaction.
Type of the selected subcategory. (e.g: "CalendarEvent")
ID of the subcategory you selected.
ID of the target you'd like to add the reaction to. (e.g: a comment id)
ID of the reaction to add.
Delete an announcement comment.
ID of an Announcement channel.
ID of the announcement where the comment is in.
ID of the comment to delete.
Delete a comment from a calendar event.
ID of the channel containing the event.
ID of the event containing the comment.
ID of the comment to delete.
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 target you'd like to add the reaction from. (e.g: a message id)
ID of the reaction.
Remove a reaction from a target from a subcategory (e.g: a comment from Forum Thread)
ID of a channel that supports reaction.
Type of the selected subcategory. (e.g: "CalendarEvent")
ID of the subcategory you selected.
ID of the target you'd like to remove the reaction to. (e.g: a comment id)
ID of the reaction to add.
Edit an existing announcement.
ID of the Announcement channel.
ID of the announcement to edit.
Edit options
Edit an announcement comment.
ID of an Announcement channel.
ID of an announcement where the comment is in.
ID of the comment to edit.
Edit options.
Edit an existing calendar event comment.
The ID of a "Calendar" channel.
The ID of an event from the channel.
The ID of the comment to edit.
Edit options.
Edit an event from a "Calendar" channel.
ID of a "Calendar" channel.
ID of a calendar event.
Edit options.
Edit a CalendarEventSeries.
ID of the channel.
ID of the event.
ID of the series.
Edit repetition 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 doc comment.
ID of the docs channel.
ID of the doc.
ID of the comment to edit.
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 a guild group.
The ID of the guild where the group to edit is in
The ID of the group to edit.
Edit options
Edit a guild role.
ID of the server
ID of the role to edit
Edit options
Edit an item from a list channel.
ID of a "Lists" channel.
ID of a list item.
Optional
options: { Edit options.
Optional
content?: stringOptional
note?: { The note of the list item
Edit a member.
ID of the guild the member is in.
ID of the the member to edit.
Edit options.
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 Symbol
s.
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
Get a specific announcement from a channel.
ID of an Announcement channel.
ID of the announcement to get.
Get a specific comment from an announcement.
ID of an Announcement channel.
ID of the announcement where the comment is in.
ID of the comment to get.
Get comments from an announcement.
ID of an Announcement channel.
ID of an announcement.
Get a list of announcements from a channel.
ID of an Announcement channel.
Optional
filter: GETChannelAnnouncementsQueryFilter to apply.
Get a ban.
ID of the guild.
ID of the banned member.
This method is used to get a list of guild ban.
ID of the guild.
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 specific event comment coming from a calendar. Note: this method doesn't cache scheduled events due to the API's restrictions.
ID of a "Calendar" channel.
ID of an event containing the comment to get.
ID of the comment to get.
This method is used to get a list of CalendarEventComment Note: due to API's restrictions, we're not able to cache scheduled events from this method.
ID of a "Calendar" channel.
ID of the event containing comments.
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 specific guild channel, if cached.
Note: this method doesn't send a rest request, it only returns cached entities.
The ID of the channel to get from cache.
Get a specific comment from a doc.
ID of the channel containing the doc.
ID of the doc the comment is in.
ID of the comment to get.
Get every comments from a doc.
ID of the channel containing the doc.
ID of the doc the comment is in.
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.
Get a guild group.
ID of the guild.
ID of the group to get.
Get guild groups.
ID of the guild.
Get guild subscriptions.
ID of the guild.
ID of the subscription to get.
Get guild subscriptions.
ID of the guild.
Returns the current max listener value for the EventEmitter
which is either
set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
v1.0.0
This method is used to get a specific guild member, if cached.
Note: this method doesn't send a rest request, it only returns cached entities.
The ID of the guild the member is in.
The ID of the member to get.
Get guild member permissions.
ID of the guild.
ID of the member.
Get a channel's message, if cached.
Note: this method doesn't send a rest request, it only returns cached entities.
ID of the guild.
ID of the channel containing the message.
ID of the message you'd like to get.
This method is used to get cached messages from a channel.
ID of the guild.
ID of a "Chat" channel.
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]By default EventEmitter
s 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
Edit Role Permission.
ID of the guild.
ID of the role.
Permissions to edit.
Change a user's status, this includes the bot's one.
User ID (@me can be used).
Status options
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
the emitter.
For EventTarget
s 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 eventName
registered 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
The emitter to query
The event name
v0.9.12
Since v3.2.0 - Use listenerCount
instead.
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());
The name of the event being listened for
Optional
options: StaticEventEmitterOptionsthat iterates eventName
events emitted by the emitter
v13.6.0, v12.16.0
Static
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!
Optional
options: StaticEventEmitterOptionsv11.13.0, v10.16.0
Optional
options: StaticEventEmitterOptionsStatic
setconst {
setMaxListeners,
EventEmitter
} = require('events');
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter | _DOMEventTarget)[]v15.4.0
Represents the bot's client.