Events

Listen to gateway events with client.on. Handlers receive hydrated structures, camelCase DTOs, or wire payloads depending on the event.

Basic Usage

Use client.on(Events.X, handler) to subscribe. Handlers receive event-specific payloads typed by ClientEvents.

javascript
import { Client, Events } from '@fluxerjs/core';

const client = new Client({ intents: 0 });

client.on(Events.Ready, () => {
  console.log('Bot is ready!');
});

client.on(Events.MessageCreate, async (message) => {
  console.log(message.content);
});

await client.login(process.env.FLUXER_BOT_TOKEN);

Payload shapes

After the major rewrite, ClientEvents payloads fall into three groups:

  1. Hydrated structures - Message, PartialMessage, Guild, Channel, GuildMember, Role, Invite, User, GuildBan, MessageReaction, GuildEmoji (via DTOs). Prefer these for bot logic.
  2. CamelCase DTOs - normalized objects from eventPayloads.ts (and a few inline camelCase shapes). Use channelId / guildId, not snake_case wire fields.
  3. Wire gateway shapes - still Gateway*DispatchData from @fluxerjs/types (snake_case). Voice events stay wire on purpose so @fluxerjs/voice can consume them unchanged.

*Update handlers that receive old/new structures may see the same instance for both args when the cache patches in place (member, channel, guild).

Common Events

javascript
client.on(Events.Ready, () => {});

client.on(Events.MessageCreate, async (message) => {});
client.on(Events.MessageUpdate, (oldMessage, newMessage) => {});
client.on(Events.MessageDelete, (message) => {}); // PartialMessage

client.on(Events.MessageReactionAdd, (payload) => {});
client.on(Events.MessageReactionRemove, (payload) => {});

client.on(Events.GuildCreate, (guild) => {});
client.on(Events.GuildUpdate, (oldGuild, newGuild) => {});
client.on(Events.GuildDelete, (guild) => {});

client.on(Events.ChannelCreate, (channel) => {});
client.on(Events.ChannelUpdate, (oldChannel, newChannel) => {});
client.on(Events.ChannelDelete, (channel) => {});

client.on(Events.GuildMemberAdd, (member) => {});
client.on(Events.GuildMemberUpdate, (oldMember, newMember) => {}); // oldMember may be null
client.on(Events.GuildMemberRemove, (member) => {});

client.on(Events.GuildRoleCreate, (role) => {});
client.on(Events.GuildRoleUpdate, ({ role, oldRole }) => {});
client.on(Events.GuildRoleDelete, ({ roleId, guildId, role }) => {});

client.on(Events.GuildBanAdd, (ban) => {});
client.on(Events.GuildBanRemove, (ban) => {});

client.on(Events.InviteCreate, (invite) => {});
client.on(Events.InviteDelete, (payload) => {
  console.log(payload.code, payload.channelId, payload.guildId);
});

client.on(Events.UserUpdate, (user) => {});

// Voice  -  wire Gateway* shapes (intentional)
client.on(Events.VoiceStateUpdate, (data) => {});
client.on(Events.VoiceServerUpdate, (data) => {});

Reaction Events

MessageReactionAdd / MessageReactionRemove emit a single camelCase DTO (MessageReactionPayload: reaction, user, messageId, channelId, emoji, userId). MessageReactionRemoveAll and MessageReactionRemoveEmoji also emit camelCase DTOs.

javascript
import { Client, Events } from '@fluxerjs/core';

const client = new Client({ intents: 0 });

client.on(Events.MessageReactionAdd, ({ reaction, user, messageId, channelId, emoji, userId }) => {
  const emojiStr = emoji.id ? `<:${emoji.name}:${emoji.id}>` : emoji.name;
  console.log(`User ${userId} reacted with ${emojiStr} on message ${messageId}`);

  if (emoji.name === '👍') {
    console.log('Someone voted yes!');
  }
});

client.on(Events.MessageReactionRemove, ({ userId, emoji, messageId }) => {
  console.log(`User ${userId} removed ${emoji.name} from message ${messageId}`);
});

client.on(Events.MessageReactionRemoveAll, (data) => {
  console.log(`All reactions cleared from message ${data.messageId}`);
});

client.on(Events.MessageReactionRemoveEmoji, (data) => {
  console.log(`All ${data.emoji.name} reactions removed from message ${data.messageId}`);
});

await client.login(process.env.FLUXER_BOT_TOKEN);

Error Handling

javascript
client.on(Events.Error, (err) => {
  console.error('Client error:', err);
});

client.on(Events.Debug, (message) => {
  console.debug(message);
});

Client Events Reference

Events exposed on Client via Events / ClientEvents. Only these names are supported - raw gateway dispatches that are not listed here are not emitted as public client events.

CategoryEvents
ConnectionReady, Resumed, Error, Debug
MessagesMessageCreate, MessageUpdate, MessageDelete, MessageDeleteBulk
ReactionsMessageReactionAdd, MessageReactionAddMany, MessageReactionRemove, MessageReactionRemoveAll, MessageReactionRemoveEmoji
GuildGuildCreate, GuildUpdate, GuildDelete, GuildCountsUpdate, GuildEmojisUpdate, GuildStickersUpdate, GuildAuditLogEntryCreate
MembersGuildMemberAdd, GuildMemberUpdate, GuildMemberRemove, GuildMembersChunk
RolesGuildRoleCreate, GuildRoleUpdate, GuildRoleDelete
ModerationGuildBanAdd, GuildBanRemove
ChannelsChannelCreate, ChannelUpdate, ChannelDelete, ChannelPinsUpdate, ChannelMemberCountsUpdate
InvitesInviteCreate, InviteDelete
Users / presenceUserUpdate, UserConnectionsUpdate, WebAuthnCredentialsUpdate, PresenceUpdate, PresenceUpdateBulk, TypingStart
WebhooksWebhooksUpdate
VoiceVoiceStateUpdate, VoiceStateAck, VoiceServerUpdate, EntranceSoundPlay, VoiceStatesSync

Event Payload Reference

Handler argument types from ClientEvents. Structure names are classes from @fluxerjs/core. DTOs are camelCase. Wire rows use Gateway* types from @fluxerjs/types (snake_case fields).

EventsHandler args
Ready(none)
Resumed(none)
ErrorError
Debugstring
MessageCreateMessage
MessageUpdateMessage | null, Message
MessageDeletePartialMessage
MessageDeleteBulkMessageDeleteBulkPayload - &#123; ids, channelId, guildId &#125;
MessageReactionAddMessageReactionPayload - { reaction, user, messageId, channelId, emoji, userId }
MessageReactionAddManyMessageReactionAddManyPayload
MessageReactionRemoveMessageReactionPayload
MessageReactionRemoveAllMessageReactionRemoveAllPayload
MessageReactionRemoveEmojiMessageReactionRemoveEmojiPayload
GuildCreateGuild
GuildUpdateGuild, Guild
GuildDeleteGuild
GuildMemberAddGuildMember
GuildMemberUpdateGuildMember | null, GuildMember (old is a clone, or null if uncached)
GuildMemberRemoveGuildMember
GuildMembersChunkGuildMembersChunkPayload
GuildCountsUpdateGuildCountsUpdatePayload
ChannelMemberCountsUpdateChannelMemberCountsUpdatePayload
GuildAuditLogEntryCreateAuditLogEntryPayload
GuildBanAddGuildBan
GuildBanRemoveGuildBan
GuildEmojisUpdateGuildEmojisUpdatePayload - { guildId, emojis }
GuildStickersUpdateGuildStickersUpdatePayload - { guildId, stickers }
GuildRoleCreateRole
GuildRoleUpdateGuildRoleUpdatePayload - { role, oldRole }
GuildRoleDeleteGuildRoleDeletePayload - { roleId, guildId, role }
ChannelCreateChannel
ChannelUpdateChannel, Channel
ChannelDeleteChannel
ChannelPinsUpdateChannelPinsUpdatePayload
InviteCreateInvite
InviteDeleteInviteDeletePayload
TypingStartTypingStartPayload
UserUpdateUser
UserConnectionsUpdateGatewayUserConnectionsUpdateDispatchData (wire)
WebAuthnCredentialsUpdateGatewayWebAuthnCredentialsUpdateDispatchData (wire)
PresenceUpdatePresenceUpdatePayload
PresenceUpdateBulkPresenceUpdateBulkPayload
WebhooksUpdateWebhooksUpdatePayload
VoiceStateUpdateGatewayVoiceStateUpdateDispatchData (wire)
VoiceStateAckGatewayVoiceStateAckDispatchData (wire)
VoiceServerUpdateGatewayVoiceServerUpdateDispatchData (wire)
EntranceSoundPlayGatewayEntranceSoundPlayDispatchData (wire)
VoiceStatesSyncGatewayVoiceStatesSyncData (wire)

CamelCase DTOs

Exported from @fluxerjs/core (defined in eventPayloads.ts). Voice events remain wire-shaped on purpose.

PayloadNotes
MessageDeleteBulkPayloadids, channelId, guildId
InviteDeletePayloadcode, guildId, channelId
TypingStartPayloadchannelId, guildId, userId, timestamp
GuildEmojisUpdatePayload / GuildStickersUpdatePayloadcached structures
MessageReactionRemoveAllPayload / RemoveEmoji / AddManycamelCase
ChannelPinsUpdatePayloadchannelId, guildId, lastPinTimestamp
PresenceUpdatePayload / PresenceUpdateBulkPayloadcamelCase
WebhooksUpdatePayloadchannelId, guildId
GuildMembersChunkPayloadincludes GuildMember[]
GuildCountsUpdatePayload / ChannelMemberCountsUpdatePayloadcamelCase counts
AuditLogEntryPayloadcamelCase audit entry
GuildRoleUpdatePayload{ role, oldRole }