agat
Types
pub opaque type CoordinatorMessage
pub type Event {
Errored(GatewayError)
Ready(grom.GatewayReadyMessage)
ResumeConfirmed
CommandPermissionsUpdated(grom.CommandPermissions)
AutoModerationRuleCreated(grom.AutoModerationRule)
AutoModerationRuleUpdated(grom.AutoModerationRule)
AutoModerationRuleDeleted(grom.AutoModerationRule)
AutoModerationActionExecuted(
grom.GatewayAutoModerationActionExecutedMessage,
)
ChannelCreated(grom.GuildChannel)
ChannelUpdated(grom.GuildChannel)
ChannelDeleted(grom.GuildChannel)
ChannelInfo(grom.GatewayChannelInfoMessage)
VoiceChannelStatusUpdated(
grom.GatewayVoiceChannelStatusUpdateMessage,
)
VoiceChannelStartTimeUpdated(
grom.GatewayVoiceChannelStartTimeUpdateMessage,
)
ThreadCreated(grom.GatewayThreadCreateMessage)
ThreadUpdated(grom.Thread)
ThreadDeleted(grom.GatewayThreadDeleteMessage)
ThreadMemberUpdated(grom.GatewayThreadMemberUpdateMessage)
ThreadMembersUpdated(grom.GatewayThreadMembersUpdateMessage)
ChannelPinsUpdated(grom.GatewayChannelPinsUpdateMessage)
EntitlementCreated(grom.Entitlement)
EntitlementUpdated(grom.Entitlement)
EntitlementDeleted(grom.Entitlement)
GuildCreated(grom.GatewayGuildCreateMessage)
GuildUpdated(grom.Guild)
GuildDeleted(grom.UnavailableGuild)
GuildBanCreated(grom.GatewayGuildBanCreateMessage)
GuildBanDeleted(grom.GatewayGuildBanDeleteMessage)
GuildEmojisUpdated(grom.GatewayGuildEmojisUpdateMessage)
GuildStickersUpdated(grom.GatewayGuildStickersUpdateMessage)
GuildMemberCreated(grom.GatewayGuildMemberCreateMessage)
GuildMemberUpdated(grom.GatewayGuildMemberUpdateMessage)
GuildMemberDeleted(grom.GatewayGuildMemberDeleteMessage)
GuildMembersChunk(grom.GatewayGuildMembersChunkMessage)
RoleCreated(grom.GatewayRoleCreateMessage)
RoleUpdated(grom.GatewayRoleUpdateMessage)
RoleDeleted(grom.GatewayRoleDeleteMessage)
ScheduledEventCreated(grom.ScheduledEvent)
ScheduledEventUpdated(grom.ScheduledEvent)
ScheduledEventDeleted(grom.ScheduledEvent)
ScheduledEventUserAdded(
grom.GatewayScheduledEventUserAddMessage,
)
ScheduledEventUserRemoved(
grom.GatewayScheduledEventUserRemoveMessage,
)
SoundboardSoundCreated(grom.SoundboardSound)
SoundboardSoundUpdated(grom.SoundboardSound)
SoundboardSoundDeleted(
grom.GatewaySoundboardSoundDeleteMessage,
)
SoundboardSounds(grom.GatewaySoundboardSoundsMessage)
IntegrationCreated(grom.GatewayIntegrationCreateMessage)
IntegrationUpdated(grom.GatewayIntegrationUpdateMessage)
IntegrationDeleted(grom.GatewayIntegrationDeleteMessage)
InviteCreated(grom.Invite)
InviteDeleted(grom.GatewayInviteDeleteMessage)
MessageCreated(grom.GatewayMessageCreateMessage)
MessageUpdated(grom.GatewayMessageUpdateMessage)
MessageDeleted(grom.GatewayMessageDeleteMessage)
MessagesBulkDeleted(grom.GatewayBulkMessageDeleteMessage)
MessageReactionCreated(
grom.GatewayMessageReactionCreateMessage,
)
MessageReactionDeleted(
grom.GatewayMessageReactionDeleteMessage,
)
AllMessageReactionsDeleted(
grom.GatewayMessageReactionDeleteAllMessage,
)
EmojiMessageReactionsDeleted(
grom.GatewayMessageReactionDeleteEmojiMessage,
)
PresenceUpdated(grom.GatewayPresenceUpdateMessage)
TypingStarted(grom.GatewayTypingStartMessage)
CurrentUserUpdated(grom.User)
VoiceChannelEffectSent(
grom.GatewayVoiceChannelEffectSendMessage,
)
VoiceStateUpdated(grom.VoiceState)
VoiceServerUpdated(grom.GatewayVoiceServerUpdateMessage)
InteractionCreated(grom.Interaction)
StageInstanceCreated(grom.StageInstance)
StageInstanceUpdated(grom.StageInstance)
StageInstanceDeleted(grom.StageInstance)
SubscriptionCreated(grom.Subscription)
SubscriptionUpdated(grom.Subscription)
SubscriptionDeleted(grom.Subscription)
PollVoteCreated(grom.GatewayPollVoteCreateMessage)
PollVoteDeleted(grom.GatewayPollVoteDeleteMessage)
RateLimited(grom.GatewayRateLimitMessage)
UnknownEvent
}
Constructors
-
Errored(GatewayError)Sent when agat comes upon an error and requires user attention to decide what to do next.
-
Ready(grom.GatewayReadyMessage)Sent when a shard is ready.
-
ResumeConfirmedSent after a session resume has finished replaying events.
-
CommandPermissionsUpdated(grom.CommandPermissions)Sent when the roles and channels where a command can be executed change.
-
AutoModerationRuleCreated(grom.AutoModerationRule) -
AutoModerationRuleUpdated(grom.AutoModerationRule) -
AutoModerationRuleDeleted(grom.AutoModerationRule) -
AutoModerationActionExecuted( grom.GatewayAutoModerationActionExecutedMessage, ) -
ChannelCreated(grom.GuildChannel) -
ChannelUpdated(grom.GuildChannel)Not sent when
last_message_idorlast_thread_idis modified. -
ChannelDeleted(grom.GuildChannel) -
ChannelInfo(grom.GatewayChannelInfoMessage)Sent in response to
request_channel_info. -
VoiceChannelStatusUpdated( grom.GatewayVoiceChannelStatusUpdateMessage, ) -
VoiceChannelStartTimeUpdated( grom.GatewayVoiceChannelStartTimeUpdateMessage, ) -
ThreadCreated(grom.GatewayThreadCreateMessage) -
ThreadUpdated(grom.Thread)Not sent when
last_message_idorlast_thread_idis modified. -
ThreadDeleted(grom.GatewayThreadDeleteMessage) -
ThreadMemberUpdated(grom.GatewayThreadMemberUpdateMessage)Sent when the current user’s thread member object is updated.
-
ThreadMembersUpdated(grom.GatewayThreadMembersUpdateMessage)Sent when anyone is added/removed from a thread.
If your application doesn’t have the
GuildMembersintent, this event will only be sent if the current user was added/removed from a thread. -
ChannelPinsUpdated(grom.GatewayChannelPinsUpdateMessage)Only sent when a message is pinned/unpinned, not when a pinned message is deleted.
-
EntitlementCreated(grom.Entitlement) -
EntitlementUpdated(grom.Entitlement) -
EntitlementDeleted(grom.Entitlement)Entitlement deletions only happen when:
- Discord issues a refund for a subscription
- Discord removes an entitlement from a user via internal tooling
- Discord deletes an app-managed entitlement
-
GuildCreated(grom.GatewayGuildCreateMessage)This event is sent if:
- the bot is initially connecting
- a new guild becomes available to the client
- the bot joins a new guild
-
GuildUpdated(grom.Guild) -
GuildDeleted(grom.UnavailableGuild)This event is sent if:
- a guild becomes unavailable (
is_unavailable == True) - the bot leaves/is removed from a guild (
is_unavailable == False)
- a guild becomes unavailable (
-
GuildBanCreated(grom.GatewayGuildBanCreateMessage)This event is only sent to bots with the
AllowBanningMembersorAllowViewingAuditLogpermissions. -
GuildBanDeleted(grom.GatewayGuildBanDeleteMessage)This event is only sent to bots with the
AllowBanningMembersorAllowViewingAuditLogpermissions. -
GuildEmojisUpdated(grom.GatewayGuildEmojisUpdateMessage) -
GuildStickersUpdated(grom.GatewayGuildStickersUpdateMessage) -
GuildMemberCreated(grom.GatewayGuildMemberCreateMessage)This event is only sent to bots with the
AllowBanningMembersorAllowViewingAuditLogpermissions. -
GuildMemberUpdated(grom.GatewayGuildMemberUpdateMessage)This event is sent when a guild member is updated. This includes
userobject changes.Requires the
GuildMembersintent. -
GuildMemberDeleted(grom.GatewayGuildMemberDeleteMessage)This event is sent when a user leaves (or gets kicked or banned) a guild.
Requires the
GuildMembersintent. -
GuildMembersChunk(grom.GatewayGuildMembersChunkMessage)Sent in response to
request_guild_members. -
RoleCreated(grom.GatewayRoleCreateMessage) -
RoleUpdated(grom.GatewayRoleUpdateMessage) -
RoleDeleted(grom.GatewayRoleDeleteMessage) -
ScheduledEventCreated(grom.ScheduledEvent) -
ScheduledEventUpdated(grom.ScheduledEvent) -
ScheduledEventDeleted(grom.ScheduledEvent) -
ScheduledEventUserAdded(grom.GatewayScheduledEventUserAddMessage)Sent when a user subscribes to a scheduled event.
-
ScheduledEventUserRemoved( grom.GatewayScheduledEventUserRemoveMessage, )Sent when a user unsubscribes from a scheduled event.
-
SoundboardSoundCreated(grom.SoundboardSound) -
SoundboardSoundUpdated(grom.SoundboardSound) -
SoundboardSoundDeleted(grom.GatewaySoundboardSoundDeleteMessage) -
SoundboardSounds(grom.GatewaySoundboardSoundsMessage)Sent in response to
request_soundboard_sounds. -
IntegrationCreated(grom.GatewayIntegrationCreateMessage) -
IntegrationUpdated(grom.GatewayIntegrationUpdateMessage) -
IntegrationDeleted(grom.GatewayIntegrationDeleteMessage) -
InviteCreated(grom.Invite)Requires the
AllowManagingChannelspermission in the target channel. -
InviteDeleted(grom.GatewayInviteDeleteMessage)Requires the
AllowManagingChannelspermission in the target channel. -
MessageCreated(grom.GatewayMessageCreateMessage) -
MessageUpdated(grom.GatewayMessageUpdateMessage) -
MessageDeleted(grom.GatewayMessageDeleteMessage) -
MessagesBulkDeleted(grom.GatewayBulkMessageDeleteMessage) -
MessageReactionCreated(grom.GatewayMessageReactionCreateMessage) -
MessageReactionDeleted(grom.GatewayMessageReactionDeleteMessage) -
AllMessageReactionsDeleted( grom.GatewayMessageReactionDeleteAllMessage, ) -
EmojiMessageReactionsDeleted( grom.GatewayMessageReactionDeleteEmojiMessage, )Sent when all reactions of a specific emojis were removed.
-
PresenceUpdated(grom.GatewayPresenceUpdateMessage)Requires the
GUILD_PRESENCESintent. -
TypingStarted(grom.GatewayTypingStartMessage) -
CurrentUserUpdated(grom.User) -
VoiceChannelEffectSent(grom.GatewayVoiceChannelEffectSendMessage) -
VoiceStateUpdated(grom.VoiceState) -
VoiceServerUpdated(grom.GatewayVoiceServerUpdateMessage)Sent when initially connecting to the voice gateway (after sending
update_voice_state) or when you’re being moved over to another voice gateway. -
InteractionCreated(grom.Interaction) -
StageInstanceCreated(grom.StageInstance) -
StageInstanceUpdated(grom.StageInstance) -
StageInstanceDeleted(grom.StageInstance) -
SubscriptionCreated(grom.Subscription)The status can be either active or inactive. You will receive a Subscription Updated dispatch when the status is updated to active.
Best practice: only grant perks when entitlements are created.
-
SubscriptionUpdated(grom.Subscription) -
SubscriptionDeleted(grom.Subscription) -
PollVoteCreated(grom.GatewayPollVoteCreateMessage) -
PollVoteDeleted(grom.GatewayPollVoteDeleteMessage) -
RateLimited(grom.GatewayRateLimitMessage) -
UnknownEvent
pub opaque type GatewayConnectionInfo
pub type GatewayError {
CouldNotDecodeEvent(error: json.DecodeError)
EventNotValidUtf8(event_payload: BitArray)
CouldNotSendEvent(
event_payload: String,
reason: collie.SocketReason,
)
}
Constructors
-
CouldNotDecodeEvent(error: json.DecodeError)An event with a malformed structure was received.
-
EventNotValidUtf8(event_payload: BitArray)A non-UTF-8 event was received.
-
CouldNotSendEvent( event_payload: String, reason: collie.SocketReason, )Collie couldn’t send the event.
pub opaque type Identification
pub opaque type ShardMessage
pub opaque type UserMessage
Values
pub fn create_connection_info(
based_on info: grom.GatewayConnectionInfo,
) -> Result(GatewayConnectionInfo, Nil)
Returns Error(Nil) on invalid connection URL.
pub fn create_identification(
token token: String,
intents intents: List(grom.GatewayIntent),
) -> Identification
Use identification_with_presence to set an initial presence.
pub fn create_names() -> Names
pub fn identification_with_presence(
identification: Identification,
presence: grom.GatewayUpdatePresenceMessage,
) -> Identification
Set an initial presence.
pub fn new(
names names: Names,
connection_info connection_info: GatewayConnectionInfo,
identification identification: Identification,
state user_state: user_state,
) -> Builder(user_state)
Create a new gateway-listening bot.
Use the state parameter to hold any state you wish for your bot to hold, such as database process names.
Use create_names to create the required process names.
Use create_connection_info to create the required connection information based
on information received from the Discord REST API.
Use create_identification to create the required information about your bot.
Use with_shards and with_shard_ids to modify the amount of shards your bot will run.
pub fn on_event(
builder: Builder(user_state),
do handler: fn(user_state, Event) -> Next(user_state),
) -> Builder(user_state)
Do not put any blocking code in the handler, delegate tasks to actors.
pub fn request_channel_info(
to names: Names,
using message: grom.GatewayChannelInfoRequestMessage,
) -> Nil
Request ephemeral information about a channel that you can only receive when connected to the gateway.
Responds with a ChannelInfo.
pub fn request_guild_members(
to names: Names,
using message: grom.GatewayGuildMembersRequestMessage,
) -> Nil
Request a list of all guild members of a guild, or only those with specific IDs.
Responds with GuildMembersChunks.
pub fn request_soundboard_sounds(
to names: Names,
of_guilds guild_ids: List(grom.Snowflake(grom.Guild)),
) -> Nil
Request a list of all soundboard sounds for a multitude of guilds.
Responds with a SoundboardSounds.
pub fn stop() -> Next(user_state)
Stopping will shutdown all shards and the coordinator without restarting them.
pub fn stop_abnormal(because reason: String) -> Next(user_state)
An abnormal stop will shutdown all shards and the coordinator, restart them, but won’t resume the shard sessions.
pub fn supervised(
builder: Builder(user_state),
) -> supervision.ChildSpecification(static_supervisor.Supervisor)
Adds the gateway connection to your supervision tree.
Use a static supervisor from gleam_otp to start the bot in your main function.
pub fn update_presence(
of names: Names,
using message: grom.GatewayUpdatePresenceMessage,
) -> Nil
Updates your bot’s presence.
Use identification_with_presence to set an initial presence
before connecting to the gateway.
pub fn update_voice_state(
of names: Names,
using message: grom.GatewayUpdateVoiceStateMessage,
) -> Nil
Connects, moves between, or disconnects your bot from a voice channel.
Responds with a VoiceServerUpdated.
pub fn with_shard_ids(
builder: Builder(user_state),
shard_ids: List(Int),
total_shard_count total_shard_count: Int,
) -> Builder(user_state)
Allows you to specify the specific shards you want to start up on this instance.
The shard count should include any shards you’re running on other instances of your bot.