Class Route

java.lang.Object
net.dv8tion.jda.api.requests.Route

public class Route extends Object
Routes for API endpoints.
  • Field Details

    • MAJOR_PARAMETER_NAMES

      public static final List<String> MAJOR_PARAMETER_NAMES
      The known major parameters used for rate-limits.

      Instead of webhook_id + webhook_token, we use interaction_token for interaction routes.

      See Also:
  • Method Details

    • custom

      @Nonnull public static Route custom(@Nonnull Method method, @Nonnull String route)
      Create a route template for the given HTTP method.

      Route syntax should include valid argument placeholders of the format: '{' argument_name '}'
      The rate-limit handling in JDA relies on the correct names of major parameters:

      • channel_id for channel routes
      • guild_id for guild routes
      • webhook_id for webhook routes
      • interaction_token for interaction routes
      For example, to compose the route to create a message in a channel:
      
       Route route = Route.custom(Method.POST, "channels/{channel_id}/messages");
       

      To compile the route, use compile(String...) with the positional arguments.

      
       Route.CompiledRoute compiled = route.compile(channelId);
       
      Parameters:
      method - The HTTP method
      route - The route template with valid argument placeholders
      Returns:
      The custom route template
      Throws:
      IllegalArgumentException - If null is provided or the route is invalid (containing spaces or empty)
    • delete

      @Nonnull public static Route delete(@Nonnull String route)
      Create a route template for the with the DELETE method.

      Route syntax should include valid argument placeholders of the format: '{' argument_name '}'
      The rate-limit handling in JDA relies on the correct names of major parameters:

      • channel_id for channel routes
      • guild_id for guild routes
      • webhook_id for webhook routes
      • interaction_token for interaction routes
      For example, to compose the route to delete a message in a channel:
      
       Route route = Route.custom(Method.DELETE, "channels/{channel_id}/messages/{message_id}");
       

      To compile the route, use compile(String...) with the positional arguments.

      
       Route.CompiledRoute compiled = route.compile(channelId, messageId);
       
      Parameters:
      route - The route template with valid argument placeholders
      Returns:
      The custom route template
      Throws:
      IllegalArgumentException - If null is provided or the route is invalid (containing spaces or empty)
    • post

      @Nonnull public static Route post(@Nonnull String route)
      Create a route template for the with the POST method.

      Route syntax should include valid argument placeholders of the format: '{' argument_name '}'
      The rate-limit handling in JDA relies on the correct names of major parameters:

      • channel_id for channel routes
      • guild_id for guild routes
      • webhook_id for webhook routes
      • interaction_token for interaction routes
      For example, to compose the route to create a message in a channel:
      
       Route route = Route.custom(Method.POST, "channels/{channel_id}/messages");
       

      To compile the route, use compile(String...) with the positional arguments.

      
       Route.CompiledRoute compiled = route.compile(channelId);
       
      Parameters:
      route - The route template with valid argument placeholders
      Returns:
      The custom route template
      Throws:
      IllegalArgumentException - If null is provided or the route is invalid (containing spaces or empty)
    • put

      @Nonnull public static Route put(@Nonnull String route)
      Create a route template for the with the PUT method.

      Route syntax should include valid argument placeholders of the format: '{' argument_name '}'
      The rate-limit handling in JDA relies on the correct names of major parameters:

      • channel_id for channel routes
      • guild_id for guild routes
      • webhook_id for webhook routes
      • interaction_token for interaction routes
      For example, to compose the route to ban a user in a guild:
      
       Route route = Route.custom(Method.PUT, "guilds/{guild_id}/bans/{user_id}");
       

      To compile the route, use compile(String...) with the positional arguments.

      
       Route.CompiledRoute compiled = route.compile(guildId, userId);
       
      Parameters:
      route - The route template with valid argument placeholders
      Returns:
      The custom route template
      Throws:
      IllegalArgumentException - If null is provided or the route is invalid (containing spaces or empty)
    • patch

      @Nonnull public static Route patch(@Nonnull String route)
      Create a route template for the with the PATCH method.

      Route syntax should include valid argument placeholders of the format: '{' argument_name '}'
      The rate-limit handling in JDA relies on the correct names of major parameters:

      • channel_id for channel routes
      • guild_id for guild routes
      • webhook_id for webhook routes
      • interaction_token for interaction routes
      For example, to compose the route to edit a message in a channel:
      
       Route route = Route.custom(Method.PATCH, "channels/{channel_id}/messages/{message_id}");
       

      To compile the route, use compile(String...) with the positional arguments.

      
       Route.CompiledRoute compiled = route.compile(channelId, messageId);
       
      Parameters:
      route - The route template with valid argument placeholders
      Returns:
      The custom route template
      Throws:
      IllegalArgumentException - If null is provided or the route is invalid (containing spaces or empty)
    • get

      @Nonnull public static Route get(@Nonnull String route)
      Create a route template for the with the GET method.

      Route syntax should include valid argument placeholders of the format: '{' argument_name '}'
      The rate-limit handling in JDA relies on the correct names of major parameters:

      • channel_id for channel routes
      • guild_id for guild routes
      • webhook_id for webhook routes
      • interaction_token for interaction routes
      For example, to compose the route to get a message in a channel:
      
       Route route = Route.custom(Method.GET, "channels/{channel_id}/messages/{message_id}");
       

      To compile the route, use compile(String...) with the positional arguments.

      
       Route.CompiledRoute compiled = route.compile(channelId, messageId);
       
      Parameters:
      route - The route template with valid argument placeholders
      Returns:
      The custom route template
      Throws:
      IllegalArgumentException - If null is provided or the route is invalid (containing spaces or empty)
    • isInteractionBucket

      public boolean isInteractionBucket()
      Whether this route is a route related to interactions.
      Interactions have some special handling, since they are exempt from global rate-limits and are limited to 15 minute uptime.
      Returns:
      True, if this route is for interactions
    • getMethod

      @Nonnull public Method getMethod()
      The Method of this route template.
      Multiple routes with different HTTP methods can share a rate-limit.
      Returns:
      The HTTP method
    • getRoute

      @Nonnull public String getRoute()
      The route template with argument placeholders.
      Returns:
      The route template
    • getParamCount

      public int getParamCount()
      The number of parameters for this route, not including query parameters.
      Returns:
      The parameter count
    • compile

      @Nonnull public Route.CompiledRoute compile(@Nonnull String... params)
      Compile the route with provided parameters.
      The number of parameters must match the number of placeholders in the route template. The provided arguments are positional and will replace the placeholders of the template in order of appearance.

      Use Route.CompiledRoute.withQueryParams(String...) to add query parameters to the route.

      Parameters:
      params - The parameters to compile the route with
      Returns:
      The compiled route, ready to use for rate-limit handling
      Throws:
      IllegalArgumentException - If the number of parameters does not match the number of placeholders, or null is provided
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object