简体   繁体   English

删除不存在的 Discord.js v13 斜杠命令

[英]Delete Discord.js v13 slash command that doesnt exist

lately, I started working on a discord bot and added slash commands.最近,我开始研究 discord 机器人并添加了斜杠命令。

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. 我注意到我有一个 ping(用 pong 回复)命令,不是我创建的,就是我创建的,但我无法摆脱它。

Here is my interactionHandler.js这是我的 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.我正在考虑获取命令的 ID,但我不知道如何获取。 Thanks for all the helpers:) Discord.js v13感谢所有帮助者:) Discord.js v13

These commands may not be refreshing because of 2 reasons:由于 2 个原因,这些命令可能不会刷新:

  • These commands may be global commands to change that to refreshing global (instead of guild) commands replace Routes.applicationGuildCommands to Routes.applicationCommands这些命令可能是全局命令,将其更改为刷新全局(而不是公会)命令将Routes.applicationGuildCommands替换为Routes.applicationCommands
  • These commands may be from a different guild which in the case you should change the guild ID这些命令可能来自不同的公会,在这种情况下你应该更改公会 ID

To figure out the problem you should do client.application.commands.fetch() to get all your commands and then console.log() the result.要找出问题,您应该执行client.application.commands.fetch()以获取所有命令,然后执行console.log()结果。

Example例子

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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