Class Client

Represents the bot's client.

Hierarchy

Constructors

Properties

cache: {
    forumThreads: TypedCollection<string | number, APIForumTopic, ForumThread, []>;
    guilds: TypedCollection<string | number, APIGuild, Guild, []>;
    members: TypedCollection<string | number, APIGuildMember, Member, [guildID: string]>;
    messages: TypedCollection<string | number, APIChatMessage, Message, [params?: {
        oldMessage?: object;
        originalMessageID?: null | string;
    }]>;
    users: TypedCollection<string | number, APIUser, User, []>;
}

Client's cache.

Type declaration

identifiers: {
    BotServerMembershipCreated: string;
    CalendarEventCreated: string;
    CalendarEventDeleted: string;
    CalendarEventRsvpDeleted: string;
    CalendarEventRsvpUpdated: string;
    CalendarEventUpdated: string;
    ChannelMessageReactionCreated: string;
    ChannelMessageReactionDeleted: string;
    ChatMessageCreated: string;
    ChatMessageDeleted: string;
    ChatMessageUpdated: string;
    DocCreated: string;
    DocDeleted: string;
    DocUpdated: string;
    ForumTopicCommentCreated: string;
    ForumTopicCommentDeleted: string;
    ForumTopicCommentUpdated: string;
    ForumTopicCreated: string;
    ForumTopicDeleted: string;
    ForumTopicLocked: string;
    ForumTopicPinned: string;
    ForumTopicReactionCreated: string;
    ForumTopicReactionDeleted: string;
    ForumTopicUnlocked: string;
    ForumTopicUnpinned: string;
    ForumTopicUpdated: string;
    ListItemCompleted: string;
    ListItemCreated: string;
    ListItemDeleted: string;
    ListItemUncompleted: string;
    ListItemUpdated: string;
    ServerChannelCreated: string;
    ServerChannelDeleted: string;
    ServerChannelUpdated: string;
    ServerMemberBanned: string;
    ServerMemberJoined: string;
    ServerMemberRemoved: string;
    ServerMemberUnbanned: string;
    ServerMemberUpdated: string;
    ServerRolesUpdated: string;
    ServerWebhookCreated: string;
    ServerWebhookUpdated: string;
}

Default event names to TouchGuild event names.

Type declaration

  • BotServerMembershipCreated: string
  • CalendarEventCreated: string
  • CalendarEventDeleted: string
  • CalendarEventRsvpDeleted: string
  • CalendarEventRsvpUpdated: string
  • CalendarEventUpdated: string
  • ChannelMessageReactionCreated: string
  • ChannelMessageReactionDeleted: string
  • ChatMessageCreated: string
  • ChatMessageDeleted: string
  • ChatMessageUpdated: string
  • DocCreated: string
  • DocDeleted: string
  • DocUpdated: string
  • ForumTopicCommentCreated: string
  • ForumTopicCommentDeleted: string
  • ForumTopicCommentUpdated: string
  • ForumTopicCreated: string
  • ForumTopicDeleted: string
  • ForumTopicLocked: string
  • ForumTopicPinned: string
  • ForumTopicReactionCreated: string
  • ForumTopicReactionDeleted: string
  • ForumTopicUnlocked: string
  • ForumTopicUnpinned: string
  • ForumTopicUpdated: string
  • ListItemCompleted: string
  • ListItemCreated: string
  • ListItemDeleted: string
  • ListItemUncompleted: string
  • ListItemUpdated: string
  • ServerChannelCreated: string
  • ServerChannelDeleted: string
  • ServerChannelUpdated: string
  • ServerMemberBanned: string
  • ServerMemberJoined: string
  • ServerMemberRemoved: string
  • ServerMemberUnbanned: string
  • ServerMemberUpdated: string
  • ServerRolesUpdated: string
  • ServerWebhookCreated: string
  • ServerWebhookUpdated: string
params: {
    REST?: boolean;
    RESTOptions?: RESTOptions;
    token: string;
}

Client's params, including bot's token & rest options.

Type declaration

  • Optional REST?: boolean
  • Optional RESTOptions?: RESTOptions
  • token: string

REST methods.

user?: UserClient

Client's user.

Websocket Manager.

captureRejectionSymbol: typeof captureRejectionSymbol
captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

defaultMaxListeners: number
errorMonitor: typeof errorMonitor

This 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.

Accessors

Methods

  • Award a member using the built-in EXP system.

    Parameters

    • guildID: string

      ID of a guild.

    • memberID: string

      ID of a member.

    • amount: number

      Amount of experience.

    Returns Promise<number>

  • Award every members of a guild having a role using the built-in EXP system.

    Parameters

    • guildID: string

      ID of a guild.

    • roleID: number

      ID of a role.

    • amount: number

      Amount of experience.

    Returns Promise<void>

  • Mark a list item as completed.

    Parameters

    • channelID: string

      ID of a "Lists" channel.

    • itemID: string

      ID of a list item.

    Returns Promise<void>

  • Create a new item in a list channel.

    Parameters

    • channelID: string

      ID of a "Lists" channel.

    • content: string

      String content of the new item.

    • Optional note: {
          content: string;
      }

      Add a note to the new item.

      • content: string

        The note of the list item

    Returns Promise<ListItem>

  • Add a reaction to a specified object.

    Parameters

    • channelID: string

      ID of a channel that supports reaction.

    • channelType: ChannelReactionTypes

      Type of the selected channel. (e.g: "ChannelMessage")

    • objectID: string | number

      ID of the object you'd like to add the reaction to. (e.g: a message id)

    • reaction: number

      ID of the reaction.

    Returns Promise<void>

  • Create a webhook

    Parameters

    • guildID: string

      ID of a guild.

    • channelID: string

      ID of a channel.

    • name: string

      Name of the new webhook.

    Returns Promise<Webhook>

  • Delete an event from a "Calendar" channel.

    Parameters

    • channelID: string

      ID of a "Calendar" channel.

    • eventID: number

      ID of a calendar event.

    Returns Promise<void>

  • Delete a RSVP from a calendar event.

    Parameters

    • channelID: string

      ID of a "Calendar" channel.

    • eventID: number

      ID of a calendar event.

    • memberID: string

      ID of a member.

    Returns Promise<void>

  • Delete a channel.

    Parameters

    • channelID: string

      ID of the channel you'd like to delete.

    Returns Promise<void>

  • Delete a doc from a "Docs" channel.

    Parameters

    • channelID: string

      ID of a "Docs" channel.

    • docID: number

      ID of a doc.

    Returns Promise<void>

  • Delete a forum thread comment.

    Parameters

    • channelID: string

      ID of a "Forums" channel.

    • threadID: number

      ID of a forum thread.

    • commentID: number

      ID of a forum thread comment.

    Returns Promise<void>

  • Delete a forum thread from a specific forum channel

    Parameters

    • channelID: string

      ID of a "Forums" channel.

    • threadID: number

      ID of a forum thread.

    Returns Promise<void>

  • Delete an item from a list channel.

    Parameters

    • channelID: string

      ID of a "Lists" channel.

    • itemID: string

      ID of a list item.

    Returns Promise<void>

  • Delete a specific message.

    Parameters

    • channelID: string

      ID of the channel containing the message.

    • messageID: string

      ID of the message you'd like to delete.

    Returns Promise<void>

  • Delete a webhook

    Parameters

    • guildID: string

      ID of a guild.

    • webhookID: string

      ID of an existent webhook.

    Returns Promise<void>

  • Disconnect from Guilded.

    Parameters

    • Optional crashOnDisconnect: boolean

      If set, throws an error to stop the process.

    Returns void

  • Edit an item from a list channel.

    Parameters

    • channelID: string

      ID of a "Lists" channel.

    • itemID: string

      ID of a list item.

    • content: string

      New item's content.

    • Optional note: {
          content: string;
      }

      Add a note to the item.

      • content: string

        The note of the list item

    Returns Promise<ListItem>

  • Edit a specific message coming from a specified channel.

    Parameters

    • channelID: string

      The ID of the channel.

    • messageID: string

      The ID of the message you'd like to edit.

    • newMessage: object

      object containing new message's options.

    Returns Promise<Message>

  • 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) ]

    Since

    v6.0.0

    Returns (string | symbol)[]

  • This method is used to get a specific calendar event.

    Note: this method requires a "Calendar" channel.

    Parameters

    • channelID: string

      ID of a Calendar channel.

    • eventID: number

      ID of a Calendar event.

    Returns Promise<CalendarEvent>

  • This method is used to get a specific CalendarEventRSVP.

    Note: this method requires a Calendar channel.

    Parameters

    • channelID: string

      ID of a Calendar channel

    • eventID: number

      ID of a Calendar Event

    • memberID: string

      ID of a Guild Member

    Returns Promise<CalendarEventRSVP>

  • This method is used to get a list of CalendarEventRSVP.

    Parameters

    • channelID: string

      ID of a "Calendar" channel.

    • eventID: number

      ID of a calendar event.

    Returns Promise<CalendarEventRSVP[]>

  • This method is used to get a specific guild channel.

    Note: You do not need a guildID to get a channel, only the channelID is needed.

    Parameters

    • channelID: string

      The ID of the channel you'd like to get.

    Returns Promise<Channel>

  • This method is used to get a channel doc.

    Note: This method requires a "Docs" channel.

    Parameters

    • channelID: string

      ID of the Docs channel.

    • docID: number

      ID of the channel doc.

    Returns Promise<Doc>

  • This method is used to get a specific forum thread comment.

    Parameters

    • channelID: string

      ID of a "Forums" channel.

    • threadID: number

      ID of a Forum thread.

    • commentID: number

      ID of a Forum thread comment.

    Returns Promise<ForumThreadComment>

  • This method is used to get a specific forum thread.

    Note: This method requires a "Forum" channel.

    Parameters

    • channelID: string

      ID of a speific Forum channel.

    • threadID: number

      ID of the specific Forum Thread.

    Returns Promise<ForumThread>

  • This method is used to get a specific Guild.

    Note: Guild = Server

    Parameters

    • guildID: string

      The ID of the guild you'd like to get.

    Returns Promise<Guild>

  • This method is used to get a specific list item.

    Parameters

    • channelID: string

      ID of a "List" channel.

    • itemID: string

      ID of a list item.

    Returns Promise<ListItem>

  • This method is used to get a list of ListItem.

    Parameters

    • channelID: string

      ID of a "List" channel.

    Returns Promise<ListItem[]>

  • Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.

    Since

    v1.0.0

    Returns number

  • This method is used to get a specific guild member.

    Parameters

    • guildID: string

      The ID of the Guild.

    • memberID: string

      The ID of the Guild Member you'd like to get.

    Returns Promise<Member>

  • This method is used to get a specific channel message

    Parameters

    • channelID: string

      ID of the channel containing the message.

    • messageID: string

      ID of the message you'd like to get.

    Returns Promise<Message>

  • This method is used to get a specific webhook.

    Parameters

    • guildID: string

      ID of a guild.

    • webhookID: string

      ID of a webhook.

    Returns Promise<Webhook>

  • This method is used to get a list of Webhook.

    Parameters

    • guildID: string

      ID of a guild.

    • channelID: string

      ID of a channel.

    Returns Promise<Webhook[]>

  • Lock a forum thread.

    Parameters

    • channelID: string

      ID of a "Forums" channel.

    • threadID: number

      ID of a forum thread.

    Returns Promise<void>

  • Add a member to a group

    Parameters

    • groupID: string

      ID of a guild group.

    • memberID: string

      ID of a member.

    Returns Promise<void>

  • Add a role to a member

    Parameters

    • guildID: string

      ID of a guild.

    • memberID: string

      ID of a member.

    • roleID: number

      ID of a role.

    Returns Promise<void>

  • Remove a member from a group

    Parameters

    • groupID: string

      ID of a guild group.

    • memberID: string

      ID of a member.

    Returns Promise<void>

  • Remove a role from a member

    Parameters

    • guildID: string

      ID of a guild.

    • memberID: string

      ID of a member.

    • roleID: number

      ID of a role.

    Returns Promise<void>

  • Pin a forum thread.

    Parameters

    • channelID: string

      ID of a "Forums" channel.

    • threadID: number

      ID of a forum thread.

    Returns Promise<void>

  • Remove a reaction from a specified message.

    Parameters

    • channelID: string

      ID of a channel that supports reaction.

    • channelType: ChannelReactionTypes

      Type of the selected channel. (e.g: "ChannelMessage")

    • objectID: string | number

      ID of the object you'd like to add the reaction to. (e.g: a message id)

    • reaction: number

      ID of the reaction.

    Returns Promise<void>

  • 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.

    Since

    v0.3.5

    Parameters

    • n: number

    Returns Client

  • Set a member's xp using the built-in EXP system.

    Parameters

    • guildID: string

      ID of a guild.

    • memberID: string

      ID of a member.

    • amount: number

      Total amount of experience.

    Returns Promise<number>

  • Mark a list item as uncompleted.

    Parameters

    • channelID: string

      ID of a "Lists" channel.

    • itemID: string

      ID of a list item.

    Returns Promise<void>

  • Unlock a forum thread.

    Parameters

    • channelID: string

      ID of a "Forums" channel.

    • threadID: number

      ID of a forum thread.

    Returns Promise<void>

  • Unpin a forum thread.

    Parameters

    • channelID: string

      ID of a "Forums" channel.

    • threadID: number

      ID of a forum thread.

    Returns Promise<void>

  • Returns 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]
    }

    Since

    v15.2.0, v14.17.0

    Parameters

    • emitter: EventEmitter | _DOMEventTarget
    • name: string | symbol

    Returns Function[]

  • A 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

    Since

    v0.9.12

    Deprecated

    Since v3.2.0 - Use listenerCount instead.

    Parameters

    • emitter: EventEmitter

      The emitter to query

    • eventName: string | symbol

      The event name

    Returns number

  • const { 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());

    Since

    v13.6.0, v12.16.0

    Returns

    that iterates eventName events emitted by the emitter

    Parameters

    • emitter: EventEmitter
    • eventName: string

      The name of the event being listened for

    • Optional options: StaticEventEmitterOptions

    Returns AsyncIterableIterator<any>

  • Creates 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!

    Since

    v11.13.0, v10.16.0

    Parameters

    • emitter: _NodeEventTarget
    • eventName: string | symbol
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

  • Parameters

    • emitter: _DOMEventTarget
    • eventName: string
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

  • const {
    setMaxListeners,
    EventEmitter
    } = require('events');

    const target = new EventTarget();
    const emitter = new EventEmitter();

    setMaxListeners(5, target, emitter);

    Since

    v15.4.0

    Parameters

    • Optional n: number

      A non-negative number. The maximum number of listeners per EventTarget event.

    • Rest ...eventTargets: (EventEmitter | _DOMEventTarget)[]

    Returns void