Skip to content

Commit

Permalink
Added getCommands() and deleteCommand() methods (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Plytas authored Feb 18, 2025
1 parent 7de6013 commit 1fb8b35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ public function createCommand(DiscordApplicationCommand $command): Response
return $this->client->post("/applications/{$applicationId}/commands", $command->toArray());
}

/**
* @return Collection<int, DiscordApplicationCommand>
*/
public function getCommands(): Collection
{
$applicationId = config('discord-interactions.application_id');

if (! is_string($applicationId)) {
throw new InvalidConfigurationException('discord-interactions.application_id');
}

return DiscordApplicationCommand::collect($this->client->throw()->get("/applications/{$applicationId}/commands")->collect());
}

public function deleteCommand(string $commandId): Response
{
$applicationId = config('discord-interactions.application_id');

if (! is_string($applicationId)) {
throw new InvalidConfigurationException('discord-interactions.application_id');
}

return $this->client->throw()->delete("/applications/{$applicationId}/commands/{$commandId}");
}

public function updateInteractionMessage(DiscordInteraction $interaction, DiscordMessage $message): Response
{
return $this->client->patch("/webhooks/{$interaction->application_id}/{$interaction->token}/messages/@original", $message->toArray());
Expand Down
2 changes: 2 additions & 0 deletions src/Facades/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

/**
* @method static Response createCommand(DiscordApplicationCommand $command)
* @method static Collection<int, DiscordApplicationCommand> getCommands()
* @method static Response deleteCommand(string $commandId)
* @method static Response updateInteractionMessage(DiscordInteraction $interaction, DiscordMessage $message)
* @method static Response deleteInteractionMessage(DiscordInteraction $interaction)
* @method static Response createMessage(string $channelId, DiscordMessage $message)
Expand Down

0 comments on commit 1fb8b35

Please sign in to comment.