glyde/role

Guild roles.

Types

POST /guilds/{g}/roles. Every field is optional and Discord supplies defaults: a role created without a name is called “new role”.

pub type CreateRole {
  CreateRole(
    name: option.Option(String),
    permissions: option.Option(permissions.Permissions),
    color: option.Option(RoleColorField),
    hoist: option.Option(Bool),
    badge: option.Option(RoleBadge),
    mentionable: option.Option(Bool),
  )
}

Constructors

PATCH /guilds/{g}/roles/{r}. Only the badge accepts null, whatever the reference page says, so only it takes a Field.

pub type EditRole {
  EditRole(
    name: option.Option(String),
    permissions: option.Option(permissions.Permissions),
    color: option.Option(RoleColorField),
    hoist: option.Option(Bool),
    badge: field.Field(RoleBadge),
    mentionable: option.Option(Bool),
  )
}

Constructors

pub type Role {
  Role(
    id: id.Id(id.Role),
    name: String,
    colors: RoleColors,
    hoist: Bool,
    icon: option.Option(String),
    unicode_emoji: option.Option(String),
    position: Int,
    permissions: permissions.Permissions,
    managed: Bool,
    mentionable: Bool,
    tags: option.Option(RoleTags),
    flags: flags.Flags(RoleFlag),
  )
}

Constructors

  • Role(
      id: id.Id(id.Role),
      name: String,
      colors: RoleColors,
      hoist: Bool,
      icon: option.Option(String),
      unicode_emoji: option.Option(String),
      position: Int,
      permissions: permissions.Permissions,
      managed: Bool,
      mentionable: Bool,
      tags: option.Option(RoleTags),
      flags: flags.Flags(RoleFlag),
    )

    Arguments

    id

    The @everyone role carries the guild’s own id.

    colors

    The one colour field. Discord still sends the deprecated color, and the decoder reads it only to fill this in when colors is missing, so there is no second number here to disagree with.

    hoist

    Listed separately in the member sidebar.

    icon

    Absent without the ROLE_ICONS feature, null on a role with no icon.

    position

    Ties are broken by id.

    permissions

    Guild-wide. The permissions on members and channels are not.

    managed

    Owned by an integration, so it cannot be assigned or deleted.

    tags

    Absent on an ordinary role.

A role wears an icon or an emoji, never both. An edit setting either one writes an explicit null over the other, so the body says what it wants rather than leaning on Discord to clear the loser.

pub type RoleBadge {
  RoleIcon(image.ImageData)
  RoleEmoji(String)
}

Constructors

  • RoleIcon(image.ImageData)

    Needs the ROLE_ICONS guild feature.

  • RoleEmoji(String)

Discord takes the role’s colour two ways and reads only one of them, so stating it twice is a body that contradicts itself. One value, one key.

pub type RoleColorField {
  LegacyColor(Int)
  Colors(RoleColors)
}

Constructors

  • LegacyColor(Int)

    The deprecated color integer, and still the only colour a guild without ENHANCED_ROLE_COLORS can set.

  • Colors(RoleColors)

    The colors object that supersedes it.

The three shapes Discord accepts. Anything else is a 400, so three numbers that can disagree would be three ways to get one. Gradient and Holographic need the ENHANCED_ROLE_COLORS feature.

pub type RoleColors {
  Solid(primary: Int)
  Gradient(primary: Int, secondary: Int)
  Holographic
}

Constructors

  • Solid(primary: Int)
  • Gradient(primary: Int, secondary: Int)
  • Holographic

    Discord accepts one holographic triple and no other, so this carries no numbers: role_colors_to_json writes them.

pub type RoleFlag {
  InPrompt
}

Constructors

  • InPrompt

    The role can be picked in an onboarding prompt.

The three booleans are a present null for true and no key for false, so they are decoded by presence and not by value.

pub type RoleTags {
  RoleTags(
    bot_id: option.Option(id.Id(id.User)),
    integration_id: option.Option(id.Id(id.Integration)),
    subscription_listing_id: option.Option(
      id.Id(id.SubscriptionListing),
    ),
    premium_subscriber: Bool,
    available_for_purchase: Bool,
    guild_connections: Bool,
  )
}

Constructors

Values

pub fn create_role() -> CreateRole
pub fn create_role_body(payload: CreateRole) -> body.Body
pub fn decoder() -> decode.Decoder(Role)
pub fn edit_role() -> EditRole
pub fn edit_role_body(payload: EditRole) -> body.Body
pub fn has_flag(
  bits: flags.Flags(RoleFlag),
  flag: RoleFlag,
) -> Bool
pub fn is_gradient(colors: RoleColors) -> Bool
pub fn role_colors_decoder() -> decode.Decoder(RoleColors)
pub fn role_colors_to_json(colors: RoleColors) -> json.Json

Every key, every time: a null clears a colour, and omitting the key keeps whatever the role already has.

pub fn role_tags_decoder() -> decode.Decoder(RoleTags)
pub fn role_tags_to_json(tags: RoleTags) -> json.Json
Search Document