glyde/guild

Guilds, called servers everywhere except the API. One record covers GET /guilds/{id}, GUILD_CREATE and GUILD_UPDATE.

The GUILD_CREATE-only block is one Option, never seven. None is REST, where the question does not apply; a GatewayCreate holding empty lists is a gateway create with nothing visible. A cache that conflates them wipes itself.

GUILD_CREATE and GUILD_DELETE read unavailable by opposite rules.

Types

Both counts or neither: with_counts=true answers with the pair, and no request produces one without the other.

pub type ApproximateCounts {
  ApproximateCounts(members: Int, presences: Int)
}

Constructors

  • ApproximateCounts(members: Int, presences: Int)
pub type Ban {
  Ban(reason: option.Option(String), user: user.User)
}

Constructors

PUT /guilds/{g}/bans/{u}.

pub type CreateBan {
  CreateBan(delete_message_seconds: option.Option(Int))
}

Constructors

  • CreateBan(delete_message_seconds: option.Option(Int))

    0 to 604800 seconds, seven days. Deletes the user’s recent messages along with the ban.

pub type ExplicitContentFilterLevel {
  FilterDisabled
  FilterMembersWithoutRoles
  FilterAllMembers
}

Constructors

  • FilterDisabled
  • FilterMembersWithoutRoles
  • FilterAllMembers

The block only GUILD_CREATE sends. It arrives together, so the fields are plain: there is no guild that knows its member count and not its channels.

pub type GatewayCreate {
  GatewayCreate(
    joined_at: String,
    large: Bool,
    member_count: Int,
    voice_states: List(voice_state.VoiceState),
    members: List(member.GuildMember),
    channels: List(channel.Channel),
    threads: List(channel.Channel),
  )
}

Constructors

  • GatewayCreate(
      joined_at: String,
      large: Bool,
      member_count: Int,
      voice_states: List(voice_state.VoiceState),
      members: List(member.GuildMember),
      channels: List(channel.Channel),
      threads: List(channel.Channel),
    )

    Arguments

    joined_at

    ISO-8601, when the bot joined.

    voice_states

    Partial: these voice states carry no guild_id.

    members

    Without the GUILD_MEMBERS intent, only the bot and the users in voice. Truncated regardless above 75 000 members.

    threads

    Active threads the bot can see, not every thread.

pub type Guild {
  Guild(
    id: id.Id(id.Guild),
    name: String,
    icon: option.Option(String),
    icon_hash: option.Option(String),
    splash: option.Option(String),
    discovery_splash: option.Option(String),
    owner_id: id.Id(id.User),
    afk_channel_id: option.Option(id.Id(id.Channel)),
    afk_timeout: Int,
    widget_enabled: option.Option(Bool),
    widget_channel_id: option.Option(id.Id(id.Channel)),
    verification_level: option.Option(VerificationLevel),
    default_message_notifications: option.Option(
      MessageNotificationLevel,
    ),
    explicit_content_filter: option.Option(
      ExplicitContentFilterLevel,
    ),
    roles: List(role.Role),
    emojis: List(emoji.GuildEmoji),
    features: List(String),
    mfa_level: option.Option(MfaLevel),
    application_id: option.Option(id.Id(id.Application)),
    system_channel_id: option.Option(id.Id(id.Channel)),
    system_channel_flags: flags.Flags(SystemChannelFlag),
    rules_channel_id: option.Option(id.Id(id.Channel)),
    max_presences: option.Option(Int),
    max_members: option.Option(Int),
    vanity_url_code: option.Option(String),
    description: option.Option(String),
    banner: option.Option(String),
    premium_tier: option.Option(PremiumTier),
    premium_subscription_count: option.Option(Int),
    preferred_locale: String,
    public_updates_channel_id: option.Option(id.Id(id.Channel)),
    max_video_channel_users: option.Option(Int),
    max_stage_video_channel_users: option.Option(Int),
    counts: option.Option(ApproximateCounts),
    nsfw_level: option.Option(GuildNsfwLevel),
    premium_progress_bar_enabled: Bool,
    safety_alerts_channel_id: option.Option(id.Id(id.Channel)),
    gateway_create: option.Option(GatewayCreate),
  )
}

Constructors

GUILD_DELETE’s payload is one of these. A GuildOutage is Discord losing the guild, so the cache keeps it; a GuildGone is the bot kicked, banned or leaving, so the cache drops it.

pub type GuildDeparture {
  GuildOutage(id.Id(id.Guild))
  GuildGone(id.Id(id.Guild))
}

Constructors

pub type GuildNsfwLevel {
  DefaultNsfwLevel
  ExplicitNsfwLevel
  SafeNsfwLevel
  AgeRestrictedNsfwLevel
}

Constructors

  • DefaultNsfwLevel
  • ExplicitNsfwLevel
  • SafeNsfwLevel
  • AgeRestrictedNsfwLevel

GUILD_CREATE’s payload is one of these. During an outage all Discord sends is the id.

pub type MaybeAvailableGuild {
  AvailableGuild(Guild)
  OfflineGuild(id.Id(id.Guild))
}

Constructors

pub type MessageNotificationLevel {
  AllMessages
  OnlyMentions
}

Constructors

  • AllMessages
  • OnlyMentions
pub type MfaLevel {
  NoMfa
  ElevatedMfa
}

Constructors

  • NoMfa
  • ElevatedMfa
pub type PremiumTier {
  NoTier
  Tier1
  Tier2
  Tier3
}

Constructors

  • NoTier
  • Tier1
  • Tier2
  • Tier3

All six are suppressions, so a set bit HIDES a notice rather than turning one on.

pub type SystemChannelFlag {
  SuppressJoinNotifications
  SuppressPremiumSubscriptions
  SuppressGuildReminderNotifications
  SuppressJoinNotificationReplies
  SuppressRoleSubscriptionPurchaseNotifications
  SuppressRoleSubscriptionPurchaseNotificationReplies
}

Constructors

  • SuppressJoinNotifications
  • SuppressPremiumSubscriptions
  • SuppressGuildReminderNotifications
  • SuppressJoinNotificationReplies
  • SuppressRoleSubscriptionPurchaseNotifications
  • SuppressRoleSubscriptionPurchaseNotificationReplies

GET /users/@me/guilds, which answers with far less than a guild: no owner_id, so decoder() rejects it. owner and permissions are relative to the requesting user and come from nowhere else.

pub type UserGuild {
  UserGuild(
    id: id.Id(id.Guild),
    name: String,
    icon: option.Option(String),
    banner: option.Option(String),
    owner: Bool,
    permissions: option.Option(permissions.Effective),
    features: List(String),
    counts: option.Option(ApproximateCounts),
  )
}

Constructors

pub type VerificationLevel {
  NoVerification
  LowVerification
  MediumVerification
  HighVerification
  VeryHighVerification
}

Constructors

  • NoVerification
  • LowVerification
  • MediumVerification
  • HighVerification
  • VeryHighVerification

Values

pub fn active_threads(
  api: api.Api,
  guild: id.Id(id.Guild),
) -> Result(channel.ActiveThreads, api.CallFailure)

GET /guilds/{guild.id}/threads/active, as List Active Guild Threads. Unpaged, so the answer is an ActiveThreads and not a ThreadList.

pub fn active_threads_call(
  guild: id.Id(id.Guild),
) -> rest.Call(channel.ActiveThreads)

The Call for [active_threads], for building the request without sending it.

pub fn add_role(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  role: id.Id(id.Role),
) -> Result(Nil, api.CallFailure)

PUT /guilds/{guild.id}/members/{user.id}/roles/{role.id}, as Add Guild Member Role.

pub fn add_role_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  role: id.Id(id.Role),
) -> rest.Call(Nil)

The Call for [add_role], for building the request without sending it.

pub fn ban(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  ban: CreateBan,
) -> Result(Nil, api.CallFailure)

PUT /guilds/{guild.id}/bans/{user.id}, as Create Guild Ban.

pub fn ban_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  ban: CreateBan,
) -> rest.Call(Nil)

The Call for [ban], for building the request without sending it.

pub fn ban_decoder() -> decode.Decoder(Ban)
pub fn ban_for(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> Result(Ban, api.CallFailure)

GET /guilds/{guild.id}/bans/{user.id}, as Get Guild Ban. Answers 404 when the user is not banned.

pub fn ban_for_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> rest.Call(Ban)

The Call for [ban_for], for building the request without sending it.

pub fn bans(
  api: api.Api,
  guild: id.Id(id.Guild),
  cursor cursor: option.Option(query.Page(id.User)),
  limit limit: option.Option(Int),
) -> Result(List(Ban), api.CallFailure)

GET /guilds/{guild.id}/bans, as Get Guild Bans. Discord caps limit at 1000. Pages by user id.

pub fn bans_call(
  guild: id.Id(id.Guild),
  cursor cursor: option.Option(query.Page(id.User)),
  limit limit: option.Option(Int),
) -> rest.Call(List(Ban))

The Call for [bans], for building the request without sending it.

pub fn channels(
  api: api.Api,
  guild: id.Id(id.Guild),
) -> Result(List(channel.Channel), api.CallFailure)

GET /guilds/{guild.id}/channels, as Get Guild Channels. Threads not included.

pub fn channels_call(
  guild: id.Id(id.Guild),
) -> rest.Call(List(channel.Channel))

The Call for [channels], for building the request without sending it.

pub fn create_ban() -> CreateBan

A ban that leaves the user’s messages where they are.

pub fn create_ban_body(payload: CreateBan) -> body.Body
pub fn create_channel(
  api: api.Api,
  guild: id.Id(id.Guild),
  create: channel.CreateChannel,
) -> Result(channel.Channel, api.CallFailure)

POST /guilds/{guild.id}/channels, as Create Guild Channel.

pub fn create_channel_call(
  guild: id.Id(id.Guild),
  create: channel.CreateChannel,
) -> rest.Call(channel.Channel)

The Call for [create_channel], for building the request without sending it.

pub fn create_role(
  api: api.Api,
  guild: id.Id(id.Guild),
  create: role.CreateRole,
) -> Result(role.Role, api.CallFailure)

POST /guilds/{guild.id}/roles, as Create Guild Role.

pub fn create_role_call(
  guild: id.Id(id.Guild),
  create: role.CreateRole,
) -> rest.Call(role.Role)

The Call for [create_role], for building the request without sending it.

pub fn decoder() -> decode.Decoder(Guild)
pub fn delete_role(
  api: api.Api,
  guild: id.Id(id.Guild),
  role_id: id.Id(id.Role),
) -> Result(Nil, api.CallFailure)

DELETE /guilds/{guild.id}/roles/{role.id}, as Delete Guild Role.

pub fn delete_role_call(
  guild: id.Id(id.Guild),
  role_id: id.Id(id.Role),
) -> rest.Call(Nil)

The Call for [delete_role], for building the request without sending it.

pub fn departure_decoder() -> decode.Decoder(GuildDeparture)

GUILD_DELETE dispatches on the KEY’s PRESENCE, not its value: present is an outage, absent is the bot being kicked, banned or leaving. A present null and a present false are both an outage.

pub fn edit_me(
  api: api.Api,
  guild: id.Id(id.Guild),
  edit: member.EditCurrentMember,
) -> Result(member.GuildMember, api.CallFailure)

PATCH /guilds/{guild.id}/members/@me, as Modify Current Member.

pub fn edit_me_call(
  guild: id.Id(id.Guild),
  edit: member.EditCurrentMember,
) -> rest.Call(member.GuildMember)

The Call for [edit_me], for building the request without sending it.

pub fn edit_member(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  edit: member.EditGuildMember,
) -> Result(member.GuildMember, api.CallFailure)

PATCH /guilds/{guild.id}/members/{user.id}, as Modify Guild Member.

pub fn edit_member_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  edit: member.EditGuildMember,
) -> rest.Call(member.GuildMember)

The Call for [edit_member], for building the request without sending it.

pub fn edit_role(
  api: api.Api,
  guild: id.Id(id.Guild),
  role_id: id.Id(id.Role),
  edit: role.EditRole,
) -> Result(role.Role, api.CallFailure)

PATCH /guilds/{guild.id}/roles/{role.id}, as Modify Guild Role.

pub fn edit_role_call(
  guild: id.Id(id.Guild),
  role_id: id.Id(id.Role),
  edit: role.EditRole,
) -> rest.Call(role.Role)

The Call for [edit_role], for building the request without sending it.

pub fn explicit_content_filter_from_int(
  value: Int,
) -> option.Option(ExplicitContentFilterLevel)
pub fn explicit_content_filter_to_int(
  value: ExplicitContentFilterLevel,
) -> Int
pub const feature_community: String
pub const feature_discoverable: String
pub const feature_enhanced_role_colors: String
pub const feature_invites_disabled: String
pub const feature_partnered: String
pub const feature_role_icons: String
pub const feature_vanity_url: String
pub const feature_verified: String
pub fn get(
  api: api.Api,
  guild: id.Id(id.Guild),
  with_counts with_counts: Bool,
) -> Result(Guild, api.CallFailure)

GET /guilds/{guild.id}, as Get Guild. with_counts adds approximate_member_count and approximate_presence_count.

pub fn get_call(
  guild: id.Id(id.Guild),
  with_counts with_counts: Bool,
) -> rest.Call(Guild)

The Call for [get], for building the request without sending it.

pub fn has_feature(
  features: List(String),
  feature: String,
) -> Bool
pub fn has_flag(
  bits: flags.Flags(SystemChannelFlag),
  flag: SystemChannelFlag,
) -> Bool
pub fn kick(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> Result(Nil, api.CallFailure)

DELETE /guilds/{guild.id}/members/{user.id}, as Remove Guild Member.

pub fn kick_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> rest.Call(Nil)

The Call for [kick], for building the request without sending it.

pub fn leave(
  api: api.Api,
  guild: id.Id(id.Guild),
) -> Result(Nil, api.CallFailure)

DELETE /users/@me/guilds/{guild.id}, as Leave Guild. Answers 204 whether or not the bot was in it.

pub fn leave_call(guild: id.Id(id.Guild)) -> rest.Call(Nil)

The Call for [leave], for building the request without sending it.

pub fn maybe_available_decoder() -> decode.Decoder(
  MaybeAvailableGuild,
)

GUILD_CREATE dispatches on the VALUE of unavailable: an available guild may still carry "unavailable": false.

pub fn member(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> Result(member.GuildMember, api.CallFailure)

GET /guilds/{guild.id}/members/{user.id}, as Get Guild Member.

pub fn member_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> rest.Call(member.GuildMember)

The Call for [member], for building the request without sending it.

pub fn members(
  api: api.Api,
  guild: id.Id(id.Guild),
  after after: option.Option(id.Id(id.User)),
  limit limit: option.Option(Int),
) -> Result(List(member.GuildMember), api.CallFailure)

GET /guilds/{guild.id}/members, as List Guild Members. Without the privileged GUILD_MEMBERS intent Discord answers 403, not a short list. Discord caps limit at 1000 and defaults it to 1.

pub fn members_call(
  guild: id.Id(id.Guild),
  after after: option.Option(id.Id(id.User)),
  limit limit: option.Option(Int),
) -> rest.Call(List(member.GuildMember))

The Call for [members], for building the request without sending it.

pub fn message_notification_level_from_int(
  value: Int,
) -> option.Option(MessageNotificationLevel)
pub fn message_notification_level_to_int(
  value: MessageNotificationLevel,
) -> Int
pub fn mfa_level_from_int(value: Int) -> option.Option(MfaLevel)
pub fn mfa_level_to_int(value: MfaLevel) -> Int
pub fn mine(
  api: api.Api,
  cursor cursor: option.Option(query.Page(id.Guild)),
  limit limit: option.Option(Int),
  with_counts with_counts: Bool,
) -> Result(List(UserGuild), api.CallFailure)

GET /users/@me/guilds, as Get Current User Guilds. A UserGuild and not a Guild: nine keys, and owner and permissions come from nowhere else. Discord caps limit at 200 and defaults it to 200. A /users route, so no guild major parameter. Pages by guild id.

pub fn mine_call(
  cursor cursor: option.Option(query.Page(id.Guild)),
  limit limit: option.Option(Int),
  with_counts with_counts: Bool,
) -> rest.Call(List(UserGuild))

The Call for [mine], for building the request without sending it.

pub fn my_member(
  api: api.Api,
  guild: id.Id(id.Guild),
) -> Result(member.GuildMember, api.CallFailure)

GET /users/@me/guilds/{guild.id}/member, as Get Current User Guild Member. A /users route, so the guild is a plain segment and every guild shares one bucket.

pub fn my_member_call(
  guild: id.Id(id.Guild),
) -> rest.Call(member.GuildMember)

The Call for [my_member], for building the request without sending it.

pub fn nsfw_level_from_int(
  value: Int,
) -> option.Option(GuildNsfwLevel)
pub fn nsfw_level_to_int(value: GuildNsfwLevel) -> Int
pub fn premium_tier_from_int(
  value: Int,
) -> option.Option(PremiumTier)
pub fn premium_tier_to_int(value: PremiumTier) -> Int
pub fn remove_role(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  role: id.Id(id.Role),
) -> Result(Nil, api.CallFailure)

DELETE /guilds/{guild.id}/members/{user.id}/roles/{role.id}, as Remove Guild Member Role.

pub fn remove_role_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
  role: id.Id(id.Role),
) -> rest.Call(Nil)

The Call for [remove_role], for building the request without sending it.

pub fn role(
  api: api.Api,
  guild: id.Id(id.Guild),
  role_id: id.Id(id.Role),
) -> Result(role.Role, api.CallFailure)

GET /guilds/{guild.id}/roles/{role.id}, as Get Guild Role.

pub fn role_call(
  guild: id.Id(id.Guild),
  role_id: id.Id(id.Role),
) -> rest.Call(role.Role)

The Call for [role], for building the request without sending it.

pub fn roles(
  api: api.Api,
  guild: id.Id(id.Guild),
) -> Result(List(role.Role), api.CallFailure)

GET /guilds/{guild.id}/roles, as Get Guild Roles.

pub fn roles_call(
  guild: id.Id(id.Guild),
) -> rest.Call(List(role.Role))

The Call for [roles], for building the request without sending it.

pub fn search_members(
  api: api.Api,
  guild: id.Id(id.Guild),
  query search: String,
  limit limit: option.Option(Int),
) -> Result(List(member.GuildMember), api.CallFailure)

GET /guilds/{guild.id}/members/search, as Search Guild Members. A prefix match on username or nickname. Discord caps limit at 1000, defaults to 1.

pub fn search_members_call(
  guild: id.Id(id.Guild),
  query search: String,
  limit limit: option.Option(Int),
) -> rest.Call(List(member.GuildMember))

The Call for [search_members], for building the request without sending it.

pub fn unban(
  api: api.Api,
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> Result(Nil, api.CallFailure)

DELETE /guilds/{guild.id}/bans/{user.id}, as Remove Guild Ban.

pub fn unban_call(
  guild: id.Id(id.Guild),
  user: id.Id(id.User),
) -> rest.Call(Nil)

The Call for [unban], for building the request without sending it.

pub fn user_guild_decoder() -> decode.Decoder(UserGuild)

GET /users/@me/guilds. A partial: nine keys, and owner_id is not one of them.

pub fn verification_level_from_int(
  value: Int,
) -> option.Option(VerificationLevel)
pub fn verification_level_to_int(value: VerificationLevel) -> Int
Search Document