我有一个错误代码:
const prefix = '-';
import fs from 'fs'
client.commands = new DiscordJS.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.cjs'));
for(const file of commandFiles){
const command = import(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('messageCreate', (message) => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ + /);
const command = args.shift().toLowerCase();
if (command === `test`){
client.commands.get('test').execute(message, args);
}
});
我的test.cjs代码:
module.exports = {
name: 'test',
description: "This is a test",
execute(message, args){
message.channel.send('Test is working');
}
}
有人知道如何帮忙吗??控制台错误消息为
如果有人能帮上忙,那就太棒了!祝你今天过得愉快!
https://i.stack.imgur.com/G6mOV.png
.cjs
是CommonJS文件,但您的代码可以在JavaScript上运行。尝试将您的分机号更改为.js
。