AlexzanderFlores / WOKCommands

130 stars 60 forks source link

slash commands still working #67

Open michahl opened 3 years ago

michahl commented 3 years ago

I deleted the slash command but its still shows up when I type /

Pomme978 commented 3 years ago

You have to delete the slash command manually. To do this you have to get the command's id and delete it with discord slash commands API. Here's a little user friendly code to get it:

 const commands = await client.api.applications(client.user.id).guilds("DEBUG GUILD ID HERE").commands.get();
  commands.forEach((e) => {
    console.log("   - Name: " + e["name"] + ", Id: " + e["id"]);
  });

This will list you all the slash commands of the bot, then you just have to get the id and delete it with:

client.api.applications(client.user.id).guilds("DEBUG GUILD ID HERE").commands("ID HERE").delete();

Here you go ^^

socratesomiliadis commented 3 years ago

When I try running the bot with the first snippet to get the IDs I get this error:

(node:7340) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of null
    at D:\AEVA-Bot\Backup\10-6-2021 - Copy\bot.js:36:60
    at Object.<anonymous> (D:\AEVA-Bot\Backup\10-6-2021 - Copy\bot.js:40:3)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7340) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7340) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Pomme978 commented 3 years ago

It may be because you don't have any slash commands registered.

jpollard-cs commented 3 years ago

note if you want to delete all slash commands you can do something like this

require('dotenv').config();

const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');

const token = process.env.TOKEN;
const clientId = process.env.CLIENT_ID;
const guildId = process.env.TEST_GUILD_ID;

const rest = new REST({ version: '9' }).setToken(token);
rest.get(Routes.applicationGuildCommands(clientId, guildId))
    .then(data => {
        const promises = [];
        for (const command of data) {
            const deleteUrl = `${Routes.applicationGuildCommands(clientId, guildId)}/${command.id}`;
            promises.push(rest.delete(deleteUrl));
        }
        return Promise.all(promises);
    })
    .then(rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }))

to do this for your global commands just use Routes.applicationCommands(clientId) instead of Routes.applicationGuildCommands(clientId, guildId)

tippfehlr commented 2 years ago

You have to delete the slash command manually. To do this you have to get the command's id and delete it with discord slash commands API. Here's a little user friendly code to get it:

 const commands = await client.api.applications(client.user.id).guilds("DEBUG GUILD ID HERE").commands.get();
  commands.forEach((e) => {
    console.log("   - Name: " + e["name"] + ", Id: " + e["id"]);
  });

This will list you all the slash commands of the bot, then you just have to get the id and delete it with:

client.api.applications(client.user.id).guilds("DEBUG GUILD ID HERE").commands("ID HERE").delete();

Here you go ^^

Even more user-friendly is just using the /slash or !slash command.

tippfehlr commented 2 years ago

It would be neat if we add an option that commands get deleted automatically.