简体   繁体   中英

Delete Discord.js v13 slash command that doesnt exist

lately, I started working on a discord bot and added slash commands.

I noticed that I have a ping(replies with pong) command that I didn't create or I did and I can't get rid of it.

Here is my interactionHandler.js

 const { REST } = require("@discordjs/rest"); const { Routes } = require("discord-api-types/v9"); module.exports = async (err, files, client) => { if (err) return console.error(err); client.interactionsArray = []; files.forEach((file) => { const interaction = require(`./../interactions/${file}`); client.interactions.set(interaction.data.name, interaction); client.interactionsArray.push(interaction.data.toJSON()); }); const rest = new REST({ version: "9" }).setToken(process.env.DISCORD_TOKEN); (async () => { try { // console.log("Refreshing slash command list"); // const guildIds = await client.guilds.cache.map((guild) => guild.id); // const clientId = await client.user.id; // guildIds.forEach(async (guildId) => { // await rest.put(Routes.applicationGuildCommands(clientId, guildId), { // body: client.interactionsArray, // }); // }); await rest.put( Routes.applicationGuildCommands("934895917453168653", "967384688069066852"), { body: client.interactionsArray}, ); console.log("Successfully refreshed slash command list"); } catch (error) { console.error(error); } })(); };

Is there a way to delete the command because I cant find a way. I was thinking of getting the ID of the command but I don't know how. Thanks for all the helpers:) Discord.js v13

These commands may not be refreshing because of 2 reasons:

  • These commands may be global commands to change that to refreshing global (instead of guild) commands replace Routes.applicationGuildCommands to Routes.applicationCommands
  • These commands may be from a different guild which in the case you should change the guild ID

To figure out the problem you should do client.application.commands.fetch() to get all your commands and then console.log() the result.

Example

//This will fetch all your slash commands
const commands = await client.application.commands.fetch();
//Returns a collection of application commands
console.log(commands);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM