agat

Types

pub opaque type Builder(user_state)
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

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 Names
pub opaque type Next(user_state)
pub opaque type ShardMessage
pub opaque type UserMessage

Values

pub fn continue(state user_state: user_state) -> Next(user_state)
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.

pub fn with_shards(
  builder: Builder(user_state),
  from from: Int,
  to to: Int,
) -> Builder(user_state)
✨ Search Document