Class AccessToken

java.lang.Object
discord4j.oauth2.object.AccessToken

public class AccessToken extends Object
Access token details for a single OAuth2 authorized client.
  • Constructor Details

    • AccessToken

      public AccessToken(discord4j.discordjson.json.AccessTokenData data)
  • Method Details

    • getData

      public discord4j.discordjson.json.AccessTokenData getData()
      Return the raw data object for this token
      Returns:
      a data object with the token details
    • getAccessToken

      public String getAccessToken()
      Return the OAuth2 access token.
      Returns:
      the OAuth2 access token
    • hasExpired

      public boolean hasExpired()
      Return whether this token has expired according to the token expires_in field and this object creation date.
      Returns:
      true if this token has expired and a refresh token flow must be used, false otherwise
    • getRefreshToken

      public Optional<String> getRefreshToken()
      Return the OAuth2 refresh token, if available.
      Returns:
      an Optional with the OAuth2 refresh token or an empty optional if not present
    • getScopes

      public EnumSet<Scope> getScopes()
      Return the OAuth2 scopes in this access token.
      Returns:
      an EnumSet of the scopes in the access token
    • getGuild

      public Optional<discord4j.discordjson.json.GuildUpdateData> getGuild()
      Return information about the guild to which your bot was added, available when authorizing a user with a Scope.BOT scope.
      Returns:
      a data object with the guild joined by your bot
      See Also:
    • getWebhook

      public Optional<discord4j.discordjson.json.WebhookData> getWebhook()
      Return webhook information if this client was authorized using a Scope.WEBHOOK_INCOMING scope. By fetching WebhookData.token() and WebhookData.id() you can send messages with the webhook.
      Returns:
      webhook details tied to this access token, if present