From 21eef87700868f46ea69ccb2572acbb178303a6f Mon Sep 17 00:00:00 2001 From: expeehaa Date: Tue, 15 Oct 2024 20:00:14 +0200 Subject: [PATCH] Support requesting global and guild commands with or without localizations. --- lib/discordrb/api/application.rb | 8 ++++---- lib/discordrb/bot.rb | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/discordrb/api/application.rb b/lib/discordrb/api/application.rb index a3ccc7170..4dfbe968f 100644 --- a/lib/discordrb/api/application.rb +++ b/lib/discordrb/api/application.rb @@ -6,12 +6,12 @@ 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.api_base}/applications/#{application_id}/commands#{"?with_localizations=#{!!with_localizations}" unless with_localizations.nil?}", Authorization: token ) end @@ -84,12 +84,12 @@ 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.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands#{"?with_localizations=#{!!with_localizations}" unless with_localizations.nil?}", Authorization: token ) end diff --git a/lib/discordrb/bot.rb b/lib/discordrb/bot.rb index 664aad982..19f462d58 100644 --- a/lib/discordrb/bot.rb +++ b/lib/discordrb/bot.rb @@ -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] - 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|