在discord.js上创建高级命令处理程序时,第一行应该是``cleient.commands-new discord



所以我正在从基本命令分支到创建高级命令处理程序,我正在关注一些youtube视频和指南,但我似乎被卡住了。我收到一个错误,上面写着Discord。Collections不是构造函数,我到处找,似乎都找不到问题的答案,所以我想向你们寻求帮助。

const { Client, Intents } = require('discord.js');
const { MessageEmbed } = require('discord.js')
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '-';
const fs = require('fs');
const Discord = require('discord.js');

//Try to debug later
client.commands = new Discord.Collections();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}

到目前为止,这就是我为它编写的代码,在大多数论坛中,它似乎都被检查过了,但我正在关注一个旧视频,所以可能discord.js将其更新为新的语法或短语?我们将不胜感激!

它是没有"s"的Collection。此外,你应该清理你的导入,因为你似乎要导入同一个模块三次。

const { Client, Intents, MessageEmbed, Collection } = require('discord.js');
...
client.commands = new Collection();

最新更新