'How to delete a Discord.js commands (v13)
I been looking all over google but still haven't find a way to delete a command I accidentally created. So I have this command call "ping" and I want to delete it. Here the code I use to create it:
// importing stuff
const DiscordJS = require("discord.js");
const dotenv = require("dotenv");
dotenv.config();
console.log("Starting up");
const client = new DiscordJS.Client({
intents: [DiscordJS.Intents.FLAGS.GUILDS, DiscordJS.Intents.FLAGS.GUILD_MESSAGES]
});
console.log("Waiting for bot to log in...");
client.on("ready", () => {
console.log("Bot Login");
const guild = client.guilds.cache.get("913238101902630983");
let commands;
if (guild) {
commands = guild.commands;
} else {
commands = client.application.commands;
}
commands.create({
name: "ping",
description: "Reply with pong"
});
});
client.login(process.env.token);
So now I want to delete that ping command. After searching google I come across 2 way to do so.
Use
client.api.applications(client.user.id).commands("command-id (interaction.data.id)").delete()the problem with this solution is I don't know how to get the commandId google searching still doesn't help. SourceUse
commands.cache.find(c => c.name === 'command name').delete();. The problem with this one is when I put the ping command name in socommands.cache.find(c => c.name === 'ping').delete();it give me this errorTypeError: Cannot read properties of undefined (reading 'delete'). Source
Please help me, Thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
