The events Lingo.Bot.handle_event/2 receives: every one Discord sends,
named as Discord names it, lowercased.
def handle_event(:message_create, %Lingo.Type.Message{content: "!ping"} = msg),
do: Lingo.Api.Message.create(msg.channel_id, "Pong!")
def handle_event(:message_delete, %Lingo.Event.MessageDelete{old: %{content: content}}),
do: Logger.info("deleted: #{content}")
def handle_event(:message_update, %{old: old, new: new}), do: ...A payload takes one of three shapes:
- a resource (
Lingo.Type.Message,Lingo.Type.Channel, ...), the same structLingo.Apireturns, when Discord sends one: creates, and deletes that carry the whole object, such as:channel_delete. %{old: t | nil, new: t}for updates of a resource.- a struct of its own in
Lingo.Event, named after Discord's event objects, for everything else: deletes that carry only ids, bans, reactions, typing and so on.
old
Updates, and deletes that carry only ids, include old: the resource as
the cache held it just before the change. It's nil when it wasn't
cached: the resource is disabled (nothing is cached by default, see
Lingo.Cache), filtered out or evicted, or Lingo never saw it. So nil
means unknown, never empty, and a handler that needs old should match
nil too. Without a cache, new in :message_update holds only the
fields Discord sent.
Unknown events
Events newer than Lingo arrive as :unknown, with a Lingo.Event.Unknown
holding Discord's name and raw payload.
Lingo's own happenings (shards connecting and disconnecting, API rate
limits) are not events but Lingo.Telemetry events; to wait until every
shard is up, use Lingo.Gateway.await_ready/1.
Gateway events
| Event | Payload |
|---|---|
:ready | Lingo.Event.Ready |
:resumed | Lingo.Event.Resumed |
:application_command_permissions_update | Lingo.Type.CommandPermissions |
:auto_moderation_rule_create | Lingo.Type.AutoModerationRule |
:auto_moderation_rule_update | %{old: old, new: new} of Lingo.Type.AutoModerationRule |
:auto_moderation_rule_delete | Lingo.Type.AutoModerationRule |
:auto_moderation_action_execution | Lingo.Event.AutoModerationAction |
:channel_create | Lingo.Type.Channel |
:channel_update | %{old: old, new: new} of Lingo.Type.Channel |
:channel_delete | Lingo.Type.Channel |
:channel_info | Lingo.Event.ChannelInfo |
:channel_pins_update | Lingo.Event.ChannelPinsUpdate |
:thread_create | Lingo.Type.Channel |
:thread_update | %{old: old, new: new} of Lingo.Type.Channel |
:thread_delete | Lingo.Event.ThreadDelete |
:thread_list_sync | Lingo.Event.ThreadListSync |
:thread_member_update | Lingo.Type.ThreadMember |
:thread_members_update | Lingo.Event.ThreadMembersUpdate |
:entitlement_create | Lingo.Type.Entitlement |
:entitlement_update | %{old: old, new: new} of Lingo.Type.Entitlement |
:entitlement_delete | Lingo.Type.Entitlement |
:guild_create | Lingo.Type.Guild |
:guild_update | %{old: old, new: new} of Lingo.Type.Guild |
:guild_delete | Lingo.Event.GuildDelete |
:guild_audit_log_entry_create | Lingo.Type.AuditLogEntry |
:guild_ban_add | Lingo.Event.GuildBan |
:guild_ban_remove | Lingo.Event.GuildBan |
:guild_emojis_update | Lingo.Event.GuildEmojisUpdate |
:guild_stickers_update | Lingo.Event.GuildStickersUpdate |
:guild_integrations_update | Lingo.Event.GuildIntegrationsUpdate |
:guild_member_add | Lingo.Type.Member |
:guild_member_update | %{old: old, new: new} of Lingo.Type.Member |
:guild_member_remove | Lingo.Event.GuildMemberRemove |
:guild_members_chunk | Lingo.Event.GuildMembersChunk |
:guild_role_create | Lingo.Type.Role |
:guild_role_update | %{old: old, new: new} of Lingo.Type.Role |
:guild_role_delete | Lingo.Event.GuildRoleDelete |
:guild_scheduled_event_create | Lingo.Type.ScheduledEvent |
:guild_scheduled_event_update | %{old: old, new: new} of Lingo.Type.ScheduledEvent |
:guild_scheduled_event_delete | Lingo.Type.ScheduledEvent |
:guild_scheduled_event_user_add | Lingo.Event.ScheduledEventUser |
:guild_scheduled_event_user_remove | Lingo.Event.ScheduledEventUser |
:guild_soundboard_sound_create | Lingo.Type.SoundboardSound |
:guild_soundboard_sound_update | %{old: old, new: new} of Lingo.Type.SoundboardSound |
:guild_soundboard_sound_delete | Lingo.Event.SoundboardSoundDelete |
:guild_soundboard_sounds_update | Lingo.Event.SoundboardSounds |
:soundboard_sounds | Lingo.Event.SoundboardSounds |
:integration_create | Lingo.Type.Integration |
:integration_update | %{old: old, new: new} of Lingo.Type.Integration |
:integration_delete | Lingo.Event.IntegrationDelete |
:interaction_create | Lingo.Type.Interaction |
:invite_create | Lingo.Type.Invite |
:invite_delete | Lingo.Event.InviteDelete |
:message_create | Lingo.Type.Message |
:message_update | %{old: old, new: new} of Lingo.Type.Message |
:message_delete | Lingo.Event.MessageDelete |
:message_delete_bulk | Lingo.Event.MessageDeleteBulk |
:message_reaction_add | Lingo.Event.Reaction |
:message_reaction_remove | Lingo.Event.Reaction |
:message_reaction_remove_all | Lingo.Event.ReactionRemoveAll |
:message_reaction_remove_emoji | Lingo.Event.Reaction |
:message_poll_vote_add | Lingo.Event.PollVote |
:message_poll_vote_remove | Lingo.Event.PollVote |
:presence_update | %{old: old, new: new} of Lingo.Type.Presence |
:rate_limited | Lingo.Event.RateLimited |
:stage_instance_create | Lingo.Type.StageInstance |
:stage_instance_update | %{old: old, new: new} of Lingo.Type.StageInstance |
:stage_instance_delete | Lingo.Type.StageInstance |
:subscription_create | Lingo.Type.Subscription |
:subscription_update | %{old: old, new: new} of Lingo.Type.Subscription |
:subscription_delete | Lingo.Type.Subscription |
:typing_start | Lingo.Event.TypingStart |
:user_update | %{old: old, new: new} of Lingo.Type.User |
:voice_channel_effect_send | Lingo.Event.VoiceChannelEffect |
:voice_channel_status_update | Lingo.Event.VoiceChannelStatus |
:voice_channel_start_time_update | Lingo.Event.VoiceChannelStartTime |
:voice_state_update | %{old: old, new: new} of Lingo.Type.VoiceState |
:webhooks_update | Lingo.Event.WebhooksUpdate |
Webhook events
These come through Lingo.Endpoint's webhook events URL. Entitlement
events come both ways: a bot with the gateway and webhook events on gets
each one twice, so deduplicate by id or subscribe to one.
| Event | Payload |
|---|---|
:application_authorized | Lingo.Event.ApplicationAuthorized |
:application_deauthorized | Lingo.Event.ApplicationDeauthorized |
:entitlement_create | Lingo.Type.Entitlement |
:entitlement_update | %{old: old, new: new} of Lingo.Type.Entitlement |
:entitlement_delete | Lingo.Type.Entitlement |
:lobby_message_create | Lingo.Type.LobbyMessage |
:lobby_message_update | %{old: old, new: new} of Lingo.Type.LobbyMessage |
:lobby_message_delete | Lingo.Event.LobbyMessageDelete |
:game_direct_message_create | Lingo.Type.Message |
:game_direct_message_update | %{old: old, new: new} of Lingo.Type.Message |
:game_direct_message_delete | Lingo.Type.Message |
Summary
Types
@type name() ::
:ready
| :resumed
| :application_command_permissions_update
| :auto_moderation_rule_create
| :auto_moderation_rule_update
| :auto_moderation_rule_delete
| :auto_moderation_action_execution
| :channel_create
| :channel_update
| :channel_delete
| :channel_info
| :channel_pins_update
| :thread_create
| :thread_update
| :thread_delete
| :thread_list_sync
| :thread_member_update
| :thread_members_update
| :entitlement_create
| :entitlement_update
| :entitlement_delete
| :guild_create
| :guild_update
| :guild_delete
| :guild_audit_log_entry_create
| :guild_ban_add
| :guild_ban_remove
| :guild_emojis_update
| :guild_stickers_update
| :guild_integrations_update
| :guild_member_add
| :guild_member_update
| :guild_member_remove
| :guild_members_chunk
| :guild_role_create
| :guild_role_update
| :guild_role_delete
| :guild_scheduled_event_create
| :guild_scheduled_event_update
| :guild_scheduled_event_delete
| :guild_scheduled_event_user_add
| :guild_scheduled_event_user_remove
| :guild_soundboard_sound_create
| :guild_soundboard_sound_update
| :guild_soundboard_sound_delete
| :guild_soundboard_sounds_update
| :soundboard_sounds
| :integration_create
| :integration_update
| :integration_delete
| :interaction_create
| :invite_create
| :invite_delete
| :message_create
| :message_update
| :message_delete
| :message_delete_bulk
| :message_reaction_add
| :message_reaction_remove
| :message_reaction_remove_all
| :message_reaction_remove_emoji
| :message_poll_vote_add
| :message_poll_vote_remove
| :presence_update
| :rate_limited
| :stage_instance_create
| :stage_instance_update
| :stage_instance_delete
| :subscription_create
| :subscription_update
| :subscription_delete
| :typing_start
| :user_update
| :voice_channel_effect_send
| :voice_channel_status_update
| :voice_channel_start_time_update
| :voice_state_update
| :webhooks_update
| :application_authorized
| :application_deauthorized
| :lobby_message_create
| :lobby_message_update
| :lobby_message_delete
| :game_direct_message_create
| :game_direct_message_update
| :game_direct_message_delete
| :unknown
An event's name.
@type payload() :: Lingo.Event.Ready.t() | Lingo.Event.Resumed.t() | Lingo.Type.CommandPermissions.t() | Lingo.Type.AutoModerationRule.t() | update(Lingo.Type.AutoModerationRule.t()) | Lingo.Event.AutoModerationAction.t() | Lingo.Type.Channel.t() | update(Lingo.Type.Channel.t()) | Lingo.Event.ChannelInfo.t() | Lingo.Event.ChannelPinsUpdate.t() | Lingo.Event.ThreadDelete.t() | Lingo.Event.ThreadListSync.t() | Lingo.Type.ThreadMember.t() | Lingo.Event.ThreadMembersUpdate.t() | Lingo.Type.Entitlement.t() | update(Lingo.Type.Entitlement.t()) | Lingo.Type.Guild.t() | update(Lingo.Type.Guild.t()) | Lingo.Event.GuildDelete.t() | Lingo.Type.AuditLogEntry.t() | Lingo.Event.GuildBan.t() | Lingo.Event.GuildEmojisUpdate.t() | Lingo.Event.GuildStickersUpdate.t() | Lingo.Event.GuildIntegrationsUpdate.t() | Lingo.Type.Member.t() | update(Lingo.Type.Member.t()) | Lingo.Event.GuildMemberRemove.t() | Lingo.Event.GuildMembersChunk.t() | Lingo.Type.Role.t() | update(Lingo.Type.Role.t()) | Lingo.Event.GuildRoleDelete.t() | Lingo.Type.ScheduledEvent.t() | update(Lingo.Type.ScheduledEvent.t()) | Lingo.Event.ScheduledEventUser.t() | Lingo.Type.SoundboardSound.t() | update(Lingo.Type.SoundboardSound.t()) | Lingo.Event.SoundboardSoundDelete.t() | Lingo.Event.SoundboardSounds.t() | Lingo.Type.Integration.t() | update(Lingo.Type.Integration.t()) | Lingo.Event.IntegrationDelete.t() | Lingo.Type.Interaction.t() | Lingo.Type.Invite.t() | Lingo.Event.InviteDelete.t() | Lingo.Type.Message.t() | update(Lingo.Type.Message.t()) | Lingo.Event.MessageDelete.t() | Lingo.Event.MessageDeleteBulk.t() | Lingo.Event.Reaction.t() | Lingo.Event.ReactionRemoveAll.t() | Lingo.Event.PollVote.t() | update(Lingo.Type.Presence.t()) | Lingo.Event.RateLimited.t() | Lingo.Type.StageInstance.t() | update(Lingo.Type.StageInstance.t()) | Lingo.Type.Subscription.t() | update(Lingo.Type.Subscription.t()) | Lingo.Event.TypingStart.t() | update(Lingo.Type.User.t()) | Lingo.Event.VoiceChannelEffect.t() | Lingo.Event.VoiceChannelStatus.t() | Lingo.Event.VoiceChannelStartTime.t() | update(Lingo.Type.VoiceState.t()) | Lingo.Event.WebhooksUpdate.t() | Lingo.Event.ApplicationAuthorized.t() | Lingo.Event.ApplicationDeauthorized.t() | Lingo.Type.LobbyMessage.t() | update(Lingo.Type.LobbyMessage.t()) | Lingo.Event.LobbyMessageDelete.t() | Lingo.Event.Unknown.t()
An event's payload. The table above says which goes with which name.
@type update(t) :: %{old: t | nil, new: t}
An update's payload: the resource before (from the cache, or nil) and after.