on

on(event: “CHANNEL_CREATE”, handler: (channel: AnyGuildChannel) => Promise<unknown>)

Subscribe to a Discord gateway event. Each overload pairs an event name constant from events with the corresponding handler signature. The handler receives typed payloads matching the event (the payload object, or a primary object with an optional old parameter for update events).

Register handlers at module scope. Weeble loads them when a deployment warms and awaits the returned promise for each dispatched event. A thrown error or rejected promise fails that dispatch and is recorded in the deployment’s runtime logs.

Example

discord.on(discord.events.GUILD_MEMBER_ADD, async (member) => {
  const channel = await discord.fetchGuildTextChannel('1504537312841961583');
  if (channel) await channel.send(`Welcome ${member.toMention()}`);
});
Parameters:
  • event — – One of the events.* constants identifying the gateway event.

  • handler — – Async callback invoked when the event fires. Signature varies by event.