Record Class DiscordChannelConfig

java.lang.Object
java.lang.Record
com.tnsai.channels.discord.DiscordChannelConfig
Record Components:
botToken - Discord bot token (no Bot prefix — the channel adds it). Required.
applicationId - Application ID for slash command registration. Optional; v1 doesn't use it but a consumer's configuration may carry it for forward-compat.
restBaseUrl - base URL for the Discord REST API. Defaults to https://discord.com/api/v10; tests override this to point at a MockWebServer. Always lacks a trailing slash.
intents - Gateway intents bitfield. Defaults to DEFAULT_INTENTS which covers DM + guild messages + message content.
reconnectInitialBackoff - initial WebSocket reconnect delay.
reconnectMaxBackoff - cap for reconnect delay.

public record DiscordChannelConfig(String botToken, String applicationId, String restBaseUrl, int intents, Duration reconnectInitialBackoff, Duration reconnectMaxBackoff) extends Record
Configuration for DiscordChannel.

Discord auth uses a single bot token (the Authorization: Bot ... header value, prefixed without quoting) for both the REST API (POST /channels/:id/messages) and the Gateway WebSocket (IDENTIFY payload). The application ID is only needed when registering slash commands — scoped out of v1 — so this record carries it as optional metadata.

Intents bitfield: Discord requires the client to declare which event categories it wants in the IDENTIFY payload. v1 needs GUILDS (1), GUILD_MESSAGES (512), DIRECT_MESSAGES (4096), and the privileged MESSAGE_CONTENT (32768) to read the actual message text — the last must be enabled separately in the Discord developer portal for the bot.

  • Field Details

    • DEFAULT_REST_BASE_URL

      public static final String DEFAULT_REST_BASE_URL
      Default base URL for the Discord REST API (v10).
      See Also:
    • DEFAULT_INTENTS

      public static final int DEFAULT_INTENTS
      GUILDS (1) | GUILD_MESSAGES (512) | DIRECT_MESSAGES (4096) | MESSAGE_CONTENT (32768).
      See Also:
    • DEFAULT_RECONNECT_INITIAL

      public static final Duration DEFAULT_RECONNECT_INITIAL
      Default initial reconnect delay — 1s.
    • DEFAULT_RECONNECT_MAX

      public static final Duration DEFAULT_RECONNECT_MAX
      Default max reconnect delay — 60s.
  • Constructor Details

    • DiscordChannelConfig

      public DiscordChannelConfig(String botToken, String applicationId, String restBaseUrl, int intents, Duration reconnectInitialBackoff, Duration reconnectMaxBackoff)
      Creates an instance of a DiscordChannelConfig record class.
      Parameters:
      botToken - the value for the botToken record component
      applicationId - the value for the applicationId record component
      restBaseUrl - the value for the restBaseUrl record component
      intents - the value for the intents record component
      reconnectInitialBackoff - the value for the reconnectInitialBackoff record component
      reconnectMaxBackoff - the value for the reconnectMaxBackoff record component
  • Method Details

    • fromEnvironment

      public static Optional<DiscordChannelConfig> fromEnvironment()
      Populate from environment variables. Missing the required DISCORD_BOT_TOKEN returns Optional.empty() so the channel can decline to start without throwing.

      Recognised vars: DISCORD_BOT_TOKEN (required), DISCORD_APPLICATION_ID (optional, slash commands), DISCORD_REST_BASE_URL (optional override for mirrors / API-version pinning), DISCORD_INTENTS (optional, integer override of the gateway intents bitfield).

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • botToken

      public String botToken()
      Returns the value of the botToken record component.
      Returns:
      the value of the botToken record component
    • applicationId

      public String applicationId()
      Returns the value of the applicationId record component.
      Returns:
      the value of the applicationId record component
    • restBaseUrl

      public String restBaseUrl()
      Returns the value of the restBaseUrl record component.
      Returns:
      the value of the restBaseUrl record component
    • intents

      public int intents()
      Returns the value of the intents record component.
      Returns:
      the value of the intents record component
    • reconnectInitialBackoff

      public Duration reconnectInitialBackoff()
      Returns the value of the reconnectInitialBackoff record component.
      Returns:
      the value of the reconnectInitialBackoff record component
    • reconnectMaxBackoff

      public Duration reconnectMaxBackoff()
      Returns the value of the reconnectMaxBackoff record component.
      Returns:
      the value of the reconnectMaxBackoff record component