Discord.js 命令处理程序正在加载文件,但未运行它们

Discord.js 命令处理程序正在加载文件,但未运行它们,discord.js,Discord.js,嗨(绝对不是专家) 使用discord.js设置命令处理程序,我知道文件正在加载,但是当我运行它们时,它们不工作(运行) 开始我的索引文件 const { prefix, token } = require("./settings/config.json"); const Discord = require("discord.js"); const fs = require("fs"); const bot = new Discord

嗨(绝对不是专家)

使用discord.js设置命令处理程序,我知道文件正在加载,但是当我运行它们时,它们不工作(运行)

开始我的索引文件

const { prefix, token }  = require("./settings/config.json");
const Discord = require("discord.js");
const fs = require("fs");
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
  const command = require(`./commands/${file}`);
  commandFiles.run(bot, message, args);
  console.log(`${file} loaded!`);
  bot.commands.set(command.name, command);
}
commands文件夹中的一个文件(已加载但未运行):

const Discord=require(“Discord.js”);
const client=new Discord.client();
让服务器图标=('https://i.imgur.com/foKcByT.png');
module.exports.run=async(bot、消息、args)=>{
//没有烫发
const noPermsErrEmbed=new Discord.MessageEmbed()
.setColor('FF6961')
.setTitle(“**错误!**”)
.setDescription(“此命令只能由工作人员使用!”)
.setTimestamp()文件
.setFooter(message.author.tag+“|Peace Keeper”,message.author.displayAvatarURL({dynamic:true,size:1024}))
如果(!message.member.hasPermission(“MANAGE_MESSAGES”))返回message.reply(noPermsErrEmbed)。然后(msg=>msg.delete(5000));
设ancArgs=args.slice(0).join(“”).split(“|”);
如果(参数长度>=3){
message.delete()。然后(()=>{
const-ancEmbed=new Discord.MessageEmbed()
.setColor(“#ABDFF2”)
.setTitle(“**”+ancArgs[0]+“**”)
.setDescription(ancArgs[1])
.setTimestamp()文件
.set缩略图(服务器图标)
.setFooter(message.author.tag+“|Peace Keeper”,message.author.displayAvatarURL({dynamic:true,size:1024}))
message.channel.send(取消嵌入);
})
}否则{
message.delete().catch();
const anterrembed=new Discord.MessageEmbed()
.setColor('FF6961')
.setTitle(“**错误!**”)
.setDescription(“使用正确的格式:!special anc |”)
.setTimestamp()文件
.setFooter(message.author.tag+“|Peace Keeper”,message.author.displayAvatarURL({dynamic:true,size:1024}))
然后(msg=>msg.delete({timeout:10000}));
}
}
module.exports.help={
名称:“特别非国大”
}

它不会运行命令,因为您使用了错误的变量来调用运行部分:

   commandFiles.run(bot, message, args);
应该是:

   command.run(bot, message, args);
commandFiles只是一个文件列表,因此它与您的命令没有直接关系

但是,您的代码有问题。 这是您的module.exports对象(在
命令
变量内):

{
运行:[异步函数],
帮助:{name:String}
}

当您使用此行时
bot.commands.set(command.name,command)
,它将无法工作,因为没有
名称
属性,它应该是
帮助.name

Discord.js版本12我忘记提到错误消息抱歉:
commandFiles.run(bot,message,args);^ReferenceError:对象上未定义消息。(C:\Users\amral\Google Drive\Jordan Discord Bot\index.js:10:25)
   command.run(bot, message, args);