斜杠命令注册来自错误文件夹discord.js14的命令



我已经厌倦了解决这个问题。首先,这是我的部署代码

const { REST, Routes } = require('discord.js');
const fs = require('node:fs');
const { client_id } = require('./config.json')
const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandFiles = fs.readdirSync('./slashCommands').filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`./slashCommands/${file}`);
commands.push(command.data.toJSON());
}
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(client_id),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();

它应该从"slashCommand"文件夹中。所以我运行'node deploy-commands.js',它工作了。问题是当我执行斜杠命令'/ping'时,我得到这个错误:

/home/runner/Nocinel/commands/ping.js:8
message.reply('🏓 **Ball is going over the net...**').then(m => { m.edit(`**🏓 Pong!n:stopwatch: Uptime: ${Math.round(message.client.uptime / 60000)} minutesn:sparkling_heart: Websocket Heartbeat: ${message.client.ws.ping}msn:round_pushpin: Rountrip Latency: ${m.createdTimestamp - message.createdTimestamp}ms**`) });
  ^
TypeError: m.edit is not a function
at /home/runner/Nocinel/commands/ping.js:8:73
repl process died unexpectedly: exit status 1

现在这个错误表明我正在运行我的"命令"中的命令。文件夹而不是我的"slashCommand"文件夹中。这没有意义,因为我明确地将其编码为只从"斜杠命令文件夹">

获取命令我重新启动,删除,等待了一个小时,并多次测试,它总是给出同样令人失望的结果。我觉得我的代码没有任何问题。

注册字符串命令没有问题(deploy- commands .js只是注册字符串命令,不使用使它们工作)。问题必须是在你的index.js你必须处理交互命令到你的文件夹slashcommands。注册命令成功。

文档:https://discordjs.guide/creating-your-bot/command-handling.html loading-command-files

相关内容