好吧,我试图了解斜杠命令,同时我根据一些视频和 github 做了一个处理程序,但是在执行斜杠命令时,抛出的错误是现有命令数量的 x 倍。 (有 3 个命令,如果我使用一个命令,控制台会收到 2 个错误)
我想机器人正在尝试执行所有命令,但我不知道它到底是什么,或者为什么!
我的代码:
const { fs, Discord, erros, colors, emojis, database } = require('../../exports.js');
const slash = [];
const arquivos = fs.readdirSync("./src/slash").filter((file) =>
file.endsWith(".js"))
module.exports = async (client) => {
for (const files of arquivos) {
const file = require(`../../slash/${files}`);
slash.push(file);
client.api.applications(client.user.id).commands.post({data: file.data})
client.ws.on('INTERACTION_CREATE', async (i) => {
const command = slash.find(cmd => cmd.data.name === i.data.name.toLowerCase())
if(command) command.execute(client, send, i);
})
async function send(interaction, content) {
return client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: await msg(interaction, content),
},
});
}
async function msg(i, c) {
const m = await Discord.APIMessage.create(client.channels.resolve(i.channel_id), c)
.resolveData()
.resolveFiles();
return { ...m.data, files: m.files }
}
}
}
module.exports.help = {
name: "ready",
title: "Comandos slashs"
}
事件处理程序正常,唯一的问题是在发送函数中,在命令中
const { Discord, erros, colors, emojis, database, titles} = require('../exports.js');
module.exports = {
data: {
name: "say",
description: "Faça o bot falar",
options: [{
name: "text",
description: "texto que vai na mensagem",
type: 3,
required: true
}]
},
async execute (client, send, i) {
var args = i.data.options
var texto = args.find(args => args.name.toLowerCase() === "text").value;
await send(i, texto)
}
}
错误:
(node:84) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown interaction at RequestHandler.execute (/home/runner /Shinobu/node_modules/discord.js/src/rest/R equestHandler.js:154:13) at processTicksAndRejections (internal/ process/task_queues.js:97:5) at async RequestHandler.push ner/Shinobu/node_modules/discord.js/src/res t/RequestHandler.js:39:14) at Object.execute (/home/runner/S hinobu/src/slash/say.js:20:5) ```
答案 0 :(得分:1)
这可能是两件事:
顺便说一句,我找不到你的代码有什么问题,所以你应该在这方面做得很好。