Class 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 Detail

      • 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 Detail

      • 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
      • 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.
      • 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.
      • 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.
      • 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.
      • 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
      • 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
      • 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
      • 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
      • getApplicationId

        public Mono<Long> getApplicationId()