Skip to content

Commit

Permalink
Support requesting global and guild commands with or without localiza…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
expeehaa committed Oct 15, 2024
1 parent ed3bd5a commit f90cb1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions lib/discordrb/api/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ module Discordrb::API::Application

# Get a list of global application commands.
# https://discord.com/developers/docs/interactions/slash-commands#get-global-application-commands
def get_global_commands(token, application_id)
def get_global_commands(token, application_id, with_localizations: nil)
Discordrb::API.request(
:applications_aid_commands,
nil,
:get,
"#{Discordrb::API.api_base}/applications/#{application_id}/commands",
Discordrb::API.uri_with_query(
"#{Discordrb::API.api_base}/applications/#{application_id}/commands",
{ with_localizations?: with_localizations }
),
Authorization: token
)
end
Expand Down Expand Up @@ -84,12 +87,15 @@ def bulk_overwrite_global_commands(token, application_id, commands)

# Get a guild's commands for an application.
# https://discord.com/developers/docs/interactions/slash-commands#get-guild-application-commands
def get_guild_commands(token, application_id, guild_id)
def get_guild_commands(token, application_id, guild_id, with_localizations: nil)
Discordrb::API.request(
:applications_aid_guilds_gid_commands,
guild_id,
:get,
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands",
Discordrb::API.uri_with_query(
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands",
{ with_localizations?: with_localizations }
),
Authorization: token
)
end
Expand Down
7 changes: 4 additions & 3 deletions lib/discordrb/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,13 @@ def prune_empty_groups

# Get all application commands.
# @param server_id [String, Integer, nil] The ID of the server to get the commands from. Global if `nil`.
# @param with_localizations [true, false] Whether the full localizations of commands should be included in the result.
# @return [Array<ApplicationCommand>]
def get_application_commands(server_id: nil)
def get_application_commands(server_id: nil, with_localizations: nil)
resp = if server_id
API::Application.get_guild_commands(@token, profile.id, server_id)
API::Application.get_guild_commands(@token, profile.id, server_id, with_localizations: with_localizations)
else
API::Application.get_global_commands(@token, profile.id)
API::Application.get_global_commands(@token, profile.id, with_localizations: with_localizations)
end

JSON.parse(resp).map do |command_data|
Expand Down

0 comments on commit f90cb1f

Please sign in to comment.