discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
985 stars 236 forks source link

How do I delete slash command? #988

Closed yoraze closed 1 year ago

yoraze commented 1 year ago

I just created test command with example from #691, but I dont know how to remove it now. I tried this (actually I just replaced save with delete that I found in AbstractRepository class):

$command = new Command($this->bot, [
    'name' => 'test',
    'description' => 'asdfghj',
    'type' => Command::CHAT_INPUT
]);
$this->bot->application->commands->delete($command);

And this isnt working so idk is there a way to remove this command?

key2peace commented 1 year ago

you need to obtain the $command->id you received upon save() in order to delete($command->id), if you don't have it, use $this->bot->application->commands->freshen()->then(function ($commands) { }); and loop through them to find it.

TigDav commented 1 year ago
    $discord->application->commands->freshen()->then(function ($commands) use ($discord) {

        foreach ($commands as $command) {
            if ($command->name == 'name'){
                $discord->application->commands->delete($command);
                break;
                }
        }

    });
yoraze commented 1 year ago

This worked, thanks! ❤️