Skip to main content
The library provides two ways to subscribe to Gateway events:
  • on_typed - receives a DispatchEvent, a typed enum. Recommended.
  • on - receives a serde_json::Value by string event name.

DispatchEvent

enum from fluxer_core::client::typed_events. All variants are marked #[non_exhaustive] - always include _ => {} in your match.

Ready

VariantFieldsDescription
Ready-Client is ready to operate. Guaranteed only after login completes.

Messages

VariantFieldsDescription
MessageCreatemessage: Message, member: Option<GuildMember>New message. member is populated when the message comes from a guild.
MessageUpdatemessage: MessageMessage was edited.
MessageDeletemessage: PartialMessageMessage was deleted. Contains only id, channel_id, guild_id.
MessageDeleteBulkids: Vec<Snowflake>, channel_id, guild_id?Multiple messages deleted at once.

Reactions

VariantFieldsDescription
MessageReactionAddreaction: MessageReactionReaction added to a message.
MessageReactionRemovereaction: MessageReactionA single reaction removed.
MessageReactionRemoveAllmessage_id, channel_id, guild_id?All reactions removed from a message.
MessageReactionRemoveEmojimessage_id, channel_id, guild_id?, emoji_name, emoji_id?All reactions for a specific emoji removed.

Guilds

VariantFieldsDescription
GuildCreateguild: GuildBot added to a guild, or existing guild data received at startup.
GuildUpdateguild: GuildGuild settings updated.
GuildDeleteguild_id: Snowflake, unavailable: boolBot removed from a guild, or the guild became unavailable.
GuildEmojisUpdateguild_id: Snowflake, emoji_ids: Vec<Snowflake>Guild emoji list updated.

Members

VariantFieldsDescription
GuildMemberAddmember: GuildMemberA new member joined the guild.
GuildMemberUpdateguild_id, user: User, nick?, roles: Vec<Snowflake>Member updated (nick, roles).
GuildMemberRemoveguild_id: Snowflake, user: UserMember left the guild.

Bans

VariantFieldsDescription
GuildBanAddban: GuildBanUser was banned. GuildBan contains guild_id, user, reason?.
GuildBanRemoveguild_id: Snowflake, user: UserBan was lifted.

Roles

VariantFieldsDescription
GuildRoleCreateguild_id: Snowflake, role: RoleRole created.
GuildRoleUpdateguild_id: Snowflake, role: RoleRole updated.
GuildRoleDeleteguild_id: Snowflake, role_id: SnowflakeRole deleted.

Channels

VariantFieldsDescription
ChannelCreatechannel: ChannelChannel created.
ChannelUpdatechannel: ChannelChannel updated.
ChannelDeletechannel: ChannelChannel deleted.

Invites

VariantFieldsDescription
InviteCreateinvite: InviteInvite created.
InviteDeletecode: String, channel_id, guild_id?Invite deleted.

Other

VariantFieldsDescription
UserUpdateuser: UserThe bot’s own user data was updated.
TypingStartchannel_id, user_id, guild_id?, timestamp: u64Someone started typing.
VoiceStateUpdatedata: GatewayVoiceStateUpdateDataVoice connection state changed.
VoiceServerUpdatedata: GatewayVoiceServerUpdateDataVoice server parameters updated.
PresenceUpdatedata: GatewayPresenceUpdateDataUser online status changed.
InteractionCreatedata: serde_json::ValueInteraction received (slash command, etc.). Passed as raw JSON - no typed representation.
Debugmessage: StringInternal diagnostic messages from the library.
Errormessage: StringInternal event processing error.
Rawevent_name: String, data: serde_json::ValueEvent with no typed variant.

MessageReaction

Structure used in MessageReactionAdd and MessageReactionRemove.
FieldTypeDescription
message_idSnowflakeMessage ID.
channel_idSnowflakeChannel ID.
guild_idOption<Snowflake>Guild ID. None in DMs.
user_idSnowflakeID of the user who reacted.
emoji_idOption<Snowflake>Custom emoji ID. None for Unicode emoji.
emoji_nameStringEmoji name or Unicode character.
emoji_animatedboolWhether the emoji is animated.

Events

String name constants for use with client.on(...).
use fluxer_core::Events;

client.on(Events::MESSAGE_CREATE, |data| async move {
    println!("{data}");
});
ConstantValue
Events::READY"READY"
Events::RESUMED"RESUMED"
Events::MESSAGE_CREATE"MESSAGE_CREATE"
Events::MESSAGE_UPDATE"MESSAGE_UPDATE"
Events::MESSAGE_DELETE"MESSAGE_DELETE"
Events::MESSAGE_DELETE_BULK"MESSAGE_DELETE_BULK"
Events::MESSAGE_REACTION_ADD"MESSAGE_REACTION_ADD"
Events::MESSAGE_REACTION_REMOVE"MESSAGE_REACTION_REMOVE"
Events::MESSAGE_REACTION_REMOVE_ALL"MESSAGE_REACTION_REMOVE_ALL"
Events::MESSAGE_REACTION_REMOVE_EMOJI"MESSAGE_REACTION_REMOVE_EMOJI"
Events::GUILD_CREATE"GUILD_CREATE"
Events::GUILD_UPDATE"GUILD_UPDATE"
Events::GUILD_DELETE"GUILD_DELETE"
Events::GUILD_MEMBER_ADD"GUILD_MEMBER_ADD"
Events::GUILD_MEMBER_UPDATE"GUILD_MEMBER_UPDATE"
Events::GUILD_MEMBER_REMOVE"GUILD_MEMBER_REMOVE"
Events::GUILD_MEMBERS_CHUNK"GUILD_MEMBERS_CHUNK"
Events::GUILD_BAN_ADD"GUILD_BAN_ADD"
Events::GUILD_BAN_REMOVE"GUILD_BAN_REMOVE"
Events::GUILD_ROLE_CREATE"GUILD_ROLE_CREATE"
Events::GUILD_ROLE_UPDATE"GUILD_ROLE_UPDATE"
Events::GUILD_ROLE_DELETE"GUILD_ROLE_DELETE"
Events::GUILD_EMOJIS_UPDATE"GUILD_EMOJIS_UPDATE"
Events::GUILD_STICKERS_UPDATE"GUILD_STICKERS_UPDATE"
Events::GUILD_INTEGRATIONS_UPDATE"GUILD_INTEGRATIONS_UPDATE"
Events::CHANNEL_CREATE"CHANNEL_CREATE"
Events::CHANNEL_UPDATE"CHANNEL_UPDATE"
Events::CHANNEL_DELETE"CHANNEL_DELETE"
Events::CHANNEL_PINS_UPDATE"CHANNEL_PINS_UPDATE"
Events::INVITE_CREATE"INVITE_CREATE"
Events::INVITE_DELETE"INVITE_DELETE"
Events::TYPING_START"TYPING_START"
Events::VOICE_STATE_UPDATE"VOICE_STATE_UPDATE"
Events::VOICE_SERVER_UPDATE"VOICE_SERVER_UPDATE"
Events::PRESENCE_UPDATE"PRESENCE_UPDATE"
Events::WEBHOOKS_UPDATE"WEBHOOKS_UPDATE"
Events::INTERACTION_CREATE"INTERACTION_CREATE"
Events::USER_UPDATE"USER_UPDATE"
Events::ERROR"ERROR"
Events::DEBUG"DEBUG"

Examples

client.on_typed(move |event| {
    Box::pin(async move {
        match event {
            DispatchEvent::MessageCreate { message, .. } => {
                println!("New message: {}", message.content);
            }
            DispatchEvent::GuildMemberAdd { member } => {
                println!("New member: {}", member.user.username);
            }
            DispatchEvent::MessageReactionAdd { reaction } => {
                println!("Reaction {} from {}", reaction.emoji_name, reaction.user_id);
            }
            DispatchEvent::GuildDelete { guild_id, unavailable } => {
                println!("Guild {guild_id} unavailable: {unavailable}");
            }
            _ => {}
        }
    })
});
client.on_typed(move |event| {
    let rest = rest.clone();
    Box::pin(async move {
        if let DispatchEvent::MessageReactionAdd { reaction } = event {
            if reaction.emoji_name == "✅" {
                if let Some(guild_id) = &reaction.guild_id {
                    let route = fluxer_types::Routes::guild_member_role(
                        guild_id,
                        &reaction.user_id,
                        "ROLE_ID_HERE",
                    );
                    let _ = rest.put_empty(&route).await;
                }
            }
        }
    })
});