Class RestClient

java.lang.Object
discord4j.rest.RestClient

public class RestClient extends Object
An aggregation of all Discord REST API resources available. Each REST resource uses its own class and uses a common Router to execute requests.
  • Constructor Details

    • RestClient

      protected RestClient(RestResources restResources)
      Create a new RestClient using the given Router as connector to perform requests.
      Parameters:
      restResources - a set of REST API resources required to operate this client
  • Method Details

    • create

      public static RestClient create(String token)
      Create a RestClient with default options, using the given token for authentication.
      Parameters:
      token - the bot token used for authentication
      Returns:
      a RestClient configured with the default options
    • restBuilder

      public static RestClientBuilder<RestClient,RouterOptions> restBuilder(String token)
      Obtain a RestClientBuilder able to create RestClient instances, using the given token for authentication.
      Parameters:
      token - the bot token used for authentication
      Returns:
      a RestClientBuilder
    • getRestResources

      public RestResources getRestResources()
      Obtain the RestResources associated with this RestClient.
      Returns:
      the current RestResources for this client
    • getChannelById

      public RestChannel getChannelById(Snowflake channelId)
      Requests to retrieve the channel represented by the supplied ID.
      Parameters:
      channelId - The ID of the channel.
      Returns:
      A RestChannel as represented by the supplied ID.
    • restChannel

      public RestChannel restChannel(discord4j.discordjson.json.ChannelData data)
      Requests to retrieve the channel represented by the supplied ChannelData.
      Parameters:
      data - The data of the channel.
      Returns:
      A RestChannel as represented by the supplied data.
    • getGuildById

      public RestGuild getGuildById(Snowflake guildId)
      Requests to retrieve the guild represented by the supplied ID.
      Parameters:
      guildId - The ID of the guild.
      Returns:
      A RestGuild as represented by the supplied ID.
    • restGuild

      public RestGuild restGuild(discord4j.discordjson.json.GuildData data)
      Requests to retrieve the guild represented by the supplied GuildData.
      Parameters:
      data - The data of the guild.
      Returns:
      A RestGuild as represented by the supplied data.
    • getGuildEmojiById

      public RestEmoji getGuildEmojiById(Snowflake guildId, Snowflake emojiId)
      Requests to retrieve the guild emoji represented by the supplied IDs.
      Parameters:
      guildId - The ID of the guild.
      emojiId - The ID of the emoji.
      Returns:
      A RestEmoji as represented by the supplied IDs.
    • restGuildEmoji

      public RestEmoji restGuildEmoji(Snowflake guildId, discord4j.discordjson.json.EmojiData data)
      Requests to retrieve the guild emoji represented by the supplied ID and EmojiData.
      Parameters:
      guildId - The ID of the guild.
      data - The data of the emoji.
      Returns:
      A RestEmoji as represented by the supplied parameters.
    • getGuildStickerById

      public RestSticker getGuildStickerById(Snowflake guildId, Snowflake stickerId)
      Requests to retrieve the guild sticker represented by the supplied IDs.
      Parameters:
      guildId - The ID of the guild.
      stickerId - The ID of the sticker.
      Returns:
      A RestSticker as represented by the supplied IDs.
    • restGuildSticker

      public RestSticker restGuildSticker(Snowflake guildId, discord4j.discordjson.json.StickerData data)
      Requests to retrieve the guild sticker represented by the supplied ID and StickerData.
      Parameters:
      guildId - The ID of the guild.
      data - The data of the sticker.
      Returns:
      A RestSticker as represented by the supplied parameters.
    • getMemberById

      public RestMember getMemberById(Snowflake guildId, Snowflake userId)
      Requests to retrieve the member represented by the supplied IDs.
      Parameters:
      guildId - The ID of the guild.
      userId - The ID of the user.
      Returns:
      A RestMember as represented by the supplied IDs.
    • restMember

      public RestMember restMember(Snowflake guildId, discord4j.discordjson.json.MemberData data)
      Requests to retrieve the member represented by the supplied ID and MemberData
      Parameters:
      guildId - The ID of the guild.
      data - The data of the user.
      Returns:
      A RestMember as represented by the supplied parameters.
    • selfRestMember

      public RestMember selfRestMember(Snowflake guildId)
      Requests to retrieve the bot member from the guild of the supplied ID
      Parameters:
      guildId - the ID of the guild.
      Returns:
      A RestMember of the bot user as represented by the supplied ID.
    • getMessageById

      public RestMessage getMessageById(Snowflake channelId, Snowflake messageId)
      Requests to retrieve the message represented by the supplied IDs.
      Parameters:
      channelId - The ID of the channel.
      messageId - The ID of the message.
      Returns:
      A RestMessage as represented by the supplied IDs.
    • restMessage

      public RestMessage restMessage(discord4j.discordjson.json.MessageData data)
      Requests to retrieve the message represented by the supplied MessageData.
      Parameters:
      data - The data of the channel.
      Returns:
      A RestMessage as represented by the supplied data.
    • getRoleById

      public RestRole getRoleById(Snowflake guildId, Snowflake roleId)
      Requests to retrieve the role represented by the supplied IDs.
      Parameters:
      guildId - The ID of the guild.
      roleId - The ID of the role.
      Returns:
      A RestRole as represented by the supplied IDs.
    • restRole

      public RestRole restRole(Snowflake guildId, discord4j.discordjson.json.RoleData data)
      Requests to retrieve the role represented by the supplied ID and RoleData.
      Parameters:
      guildId - The ID of the guild.
      data - The data of the role.
      Returns:
      A RestRole as represented by the supplied parameters.
    • getScheduledEventById

      public RestScheduledEvent getScheduledEventById(Snowflake guildId, Snowflake eventId)
      Requests to retrieve the scheduled event represented by the supplied ID.
      Parameters:
      guildId - The ID of the guild
      eventId - The ID of the event
      Returns:
      A RestScheduledEvent as represented by the supplied IDs.
    • restScheduledEvent

      public RestScheduledEvent restScheduledEvent(Snowflake guildId, discord4j.discordjson.json.GuildScheduledEventData data)
    • getUserById

      public RestUser getUserById(Snowflake userId)
      Requests to retrieve the user represented by the supplied ID.
      Parameters:
      userId - The ID of the user.
      Returns:
      A RestUser as represented by the supplied ID.
    • restUser

      public RestUser restUser(discord4j.discordjson.json.UserData data)
      Requests to retrieve the user represented by the supplied UserData.
      Parameters:
      data - The data of the user.
      Returns:
      A RestUser as represented by the supplied data.
    • getWebhookById

      public RestWebhook getWebhookById(Snowflake webhookId)
      Requests to retrieve the webhook represented by the supplied ID.
      Parameters:
      webhookId - The ID of the webhook.
      Returns:
      A RestWebhook as represented by the supplied ID.
    • restWebhook

      public RestWebhook restWebhook(discord4j.discordjson.json.WebhookData data)
      Requests to retrieve the webhook represented by the supplied WebhookData.
      Parameters:
      data - The data of the webhook.
      Returns:
      A RestWebhook as represented by the supplied ID.
    • getApplicationInfo

      public Mono<discord4j.discordjson.json.ApplicationInfoData> getApplicationInfo()
      Requests to retrieve the application info.
      Returns:
      A Mono where, upon successful completion, emits the ApplicationInfoData. If an error is received, it is emitted through the Mono.
    • getGuilds

      public Flux<discord4j.discordjson.json.UserGuildData> getGuilds()
      Requests to retrieve the guilds the current client is in.
      Returns:
      A Flux that continually emits the guilds that the current client is in. If an error is received, it is emitted through the Flux.
    • getRegions

      public Flux<discord4j.discordjson.json.RegionData> getRegions()
      Requests to retrieve the voice regions that are available.
      Returns:
      A Flux that continually emits the regions that are available. If an error is received, it is emitted through the Flux.
    • getSelf

      public Mono<discord4j.discordjson.json.UserData> getSelf()
      Requests to retrieve the bot user.
      Returns:
      A Mono where, upon successful completion, emits the bot user. If an error is received, it is emitted through the Mono.
    • getSelfMember

      public Mono<discord4j.discordjson.json.MemberData> getSelfMember(Snowflake guildId)
      Requests to retrieve the bot user, represented as a member of the guild of the supplied ID
      Parameters:
      guildId - The ID of the guild
      Returns:
      a Mono where, upon successful completion, emits the bot member. If an error is received, it is emitted through the Mono.
    • createGuild

      public Mono<discord4j.discordjson.json.GuildUpdateData> createGuild(discord4j.discordjson.json.GuildCreateRequest request)
      Requests to create a guild.
      Parameters:
      request - A GuildCreateRequest as request body.
      Returns:
      A Mono where, upon successful completion, emits the created GuildUpdateData. If an error is received, it is emitted through the Mono.
    • getInvite

      public Mono<discord4j.discordjson.json.InviteData> getInvite(String inviteCode)
      Requests to retrieve an invite.
      Parameters:
      inviteCode - The code for the invite (e.g. "xdYkpp").
      Returns:
      A Mono where, upon successful completion, emits the InviteData as represented by the supplied invite code. If an error is received, it is emitted through the Mono.
    • getInvite

      public Mono<discord4j.discordjson.json.InviteData> getInvite(String inviteCode, boolean withCounts, boolean withExpiration, @Nullable Snowflake guildScheduledEventId)
      Requests to retrieve an invite.
      Parameters:
      inviteCode - The code for the invite (e.g. "xdYkpp").
      withCounts - whether the invite should contain approximate member counts
      withExpiration - whether the invite should contain the expiration date
      guildScheduledEventId - the guild scheduled event to include with the invite, can be null
      Returns:
      A Mono where, upon successful completion, emits the InviteData as represented by the supplied invite code. If an error is received, it is emitted through the Mono.
    • getTemplate

      public Mono<discord4j.discordjson.json.TemplateData> getTemplate(String templateCode)
      Requests to retrieve an template.
      Parameters:
      templateCode - The code for the template (e.g. "hgM48av5Q69A").
      Returns:
      A Mono where, upon successful completion, emits the TemplateData as represented by the supplied template code. If an error is received, it is emitted through the Mono.
    • edit

      public Mono<discord4j.discordjson.json.UserData> edit(discord4j.discordjson.json.UserModifyRequest request)
      Requests to edit this client (i.e., modify the current bot user).
      Parameters:
      request - A UserModifyRequest as request body.
      Returns:
      A Mono where, upon successful completion, emits the edited UserData. If an error is received, it is emitted through the Mono.
    • getStageInstance

      public Mono<discord4j.discordjson.json.StageInstanceData> getStageInstance(Snowflake channelId)
      Requests to retrieve a stage instance.
      Parameters:
      channelId - The channel id associated to the stage instance.
      Returns:
      A Mono where, upon successful completion, emits the StageInstanceData associated to the supplied channel ID. If an error is received, it is emitted through the Mono.
    • getApplicationService

      public ApplicationService getApplicationService()
      Access a low-level representation of the API endpoints for the Application resource.
      Returns:
      a handle to perform low-level requests to the API
    • getAuditLogService

      public AuditLogService getAuditLogService()
      Access a low-level representation of the API endpoints for the Audit Log resource.
      Returns:
      a handle to perform low-level requests to the API
    • getChannelService

      public ChannelService getChannelService()
      Access a low-level representation of the API endpoints for the Channel resource. It is recommended you use methods like getChannelById(Snowflake), restChannel(ChannelData) or RestChannel.create(RestClient, Snowflake).
      Returns:
      a handle to perform low-level requests to the API
    • getEmojiService

      public EmojiService getEmojiService()
      Access a low-level representation of the API endpoints for the Guild Emoji resource. It is recommended you use methods like getGuildEmojiById(Snowflake, Snowflake), restGuildEmoji(Snowflake, EmojiData) or RestEmoji.create(RestClient, Snowflake, Snowflake).
      Returns:
      a handle to perform low-level requests to the API
    • getStickerService

      public StickerService getStickerService()
      Access a low-level representation of the API endpoints for the Guild Sticker resource. It is recommended you use methods like getGuildStickerById(Snowflake, Snowflake), restGuildSticker(Snowflake, StickerData) or RestSticker.create(RestClient, Snowflake, Snowflake).
      Returns:
      a handle to perform low-level requests to the API
    • getGatewayService

      public GatewayService getGatewayService()
      Access a low-level representation of the API endpoints for the Gateway resource.
      Returns:
      a handle to perform low-level requests to the API
    • getGuildService

      public GuildService getGuildService()
      Access a low-level representation of the API endpoints for the Guild resource. It is recommended you use methods like getGuildById(Snowflake), restGuild(GuildData) or RestGuild.create(RestClient, Snowflake).
      Returns:
      a handle to perform low-level requests to the API
    • getInteractionService

      public InteractionService getInteractionService()
      Access a low-level representation of the API endpoints for the Interaction resource.
      Returns:
      a handle to perform low-level requests to the API
    • getInviteService

      public InviteService getInviteService()
      Access a low-level representation of the API endpoints for the Invite resource. It is recommended you use methods like getInvite(String), or RestInvite.create(RestClient, String).
      Returns:
      a handle to perform low-level requests to the API
    • getStageInstanceService

      public StageInstanceService getStageInstanceService()
      Access a low-level representation of the API endpoints for the Stage Instance resource. It is recommended you use the getStageInstance(Snowflake) method.
      Returns:
      a handle to perform low-level requests to the API
    • getTemplateService

      public TemplateService getTemplateService()
      Access a low-level representation of the API endpoints for the Template resource. It is recommended you use methods like getTemplate(String), or RestGuildTemplate.create(RestClient, String).
      Returns:
      a handle to perform low-level requests to the API
    • getUserService

      public UserService getUserService()
      Access a low-level representation of the API endpoints for the User resource. It is recommended you use methods like getUserById(Snowflake), restUser(UserData) or RestUser.create(RestClient, Snowflake).
      Returns:
      a handle to perform low-level requests to the API
    • getVoiceService

      public VoiceService getVoiceService()
      Access a low-level representation of the API endpoints for the Voice Region resource.
      Returns:
      a handle to perform low-level requests to the API
    • getWebhookService

      public WebhookService getWebhookService()
      Access a low-level representation of the API endpoints for the Webhook resource. It is recommended you use methods like getWebhookById(Snowflake), restWebhook(WebhookData) or RestWebhook.create(RestClient, Snowflake).
      Returns:
      a handle to perform low-level requests to the API
    • getAutoModService

      public AutoModService getAutoModService()
      Access a low-level representation of the API endpoints for the AutoMod resource.
      Returns:
      a handle to perform low-level requests to the API
    • getApplicationId

      public Mono<Long> getApplicationId()