diff --git a/src/Rest/GuildCommand.php b/src/Rest/GuildCommand.php index 26de3b4d..d1a4e8af 100644 --- a/src/Rest/GuildCommand.php +++ b/src/Rest/GuildCommand.php @@ -14,6 +14,11 @@ */ class GuildCommand extends HttpResource { + /** + * @see https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command + * + * @return ExtendedPromiseInterface<\Ragnarok\Fenrir\Parts\ApplicationCommand[]> + */ public function getCommands(string $guildId, string $applicationId, bool $withLocalizations = false): ExtendedPromiseInterface { $endpoint = Endpoint::bind(Endpoint::GUILD_APPLICATION_COMMANDS, $applicationId, $guildId); diff --git a/src/Rest/Helpers/Command/CommandOptionBuilder.php b/src/Rest/Helpers/Command/CommandOptionBuilder.php index 21d93080..9cc0a9a3 100644 --- a/src/Rest/Helpers/Command/CommandOptionBuilder.php +++ b/src/Rest/Helpers/Command/CommandOptionBuilder.php @@ -119,18 +119,23 @@ public function getRequired(): ?bool * * @param array $localizedNames `key => locale`, `value => description` */ - public function addChoice(string $name, string|int|float $value, array $localizedNames = []): self + public function addChoice(string $name, string|int|float $value, ?array $localizedNames = null): self { if (!isset($this->data['choices'])) { $this->data['choices'] = []; } - $this->data['choices'][] = [ + $choice = [ 'name' => $name, - 'name_localizations' => $localizedNames, 'value' => $value, ]; + if ($localizedNames) { + $choice['name_localizations'] = $localizedNames; + } + + $this->data['choices'][] = $choice; + return $this; } diff --git a/tests/Rest/Helpers/Command/CommandOptionBuilderTest.php b/tests/Rest/Helpers/Command/CommandOptionBuilderTest.php index e5d3d871..95cbb4a0 100644 --- a/tests/Rest/Helpers/Command/CommandOptionBuilderTest.php +++ b/tests/Rest/Helpers/Command/CommandOptionBuilderTest.php @@ -90,13 +90,13 @@ public function testAddChoice(): void $builder->addChoice('choice-2', 'choice-value-2'); $this->assertEquals([ - ['name' => 'choice-1', 'value' => 'choice-value-1', 'name_localizations' => []], - ['name' => 'choice-2', 'value' => 'choice-value-2', 'name_localizations' => []] + ['name' => 'choice-1', 'value' => 'choice-value-1'], + ['name' => 'choice-2', 'value' => 'choice-value-2'] ], $builder->getChoices()); $this->assertEquals([ - ['name' => 'choice-1', 'value' => 'choice-value-1', 'name_localizations' => []], - ['name' => 'choice-2', 'value' => 'choice-value-2', 'name_localizations' => []] + ['name' => 'choice-1', 'value' => 'choice-value-1'], + ['name' => 'choice-2', 'value' => 'choice-value-2'] ], $builder->get()['choices']); }