【发布时间】:2021-01-13 04:54:57
【问题描述】:
嗨(绝对不是专家)
使用 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);
}
命令文件夹中的一个文件(加载但不运行):
const Discord = require("discord.js");
const client = new Discord.Client();
let servericon = ('https://i.imgur.com/foKcByT.png');
module.exports.run = async (bot, message, args) => {
// No Perms Embed
const noPermsErrEmbed = new Discord.MessageEmbed()
.setColor('FF6961')
.setTitle("**error!**")
.setDescription("This command can only be used by staff!")
.setTimestamp()
.setFooter(message.author.tag + " | Peace Keeper", message.author.displayAvatarURL({dynamic: true, size: 1024}))
if(!message.member.hasPermission("MANAGE_MESSAGES")) return message.reply(noPermsErrEmbed).then(msg => msg.delete(5000));
let ancArgs = args.slice(0).join(" ").split('|');
if (args.length >= 3) {
message.delete().then(() => {
const ancEmbed = new Discord.MessageEmbed()
.setColor('#ABDFF2')
.setTitle("** " + ancArgs[0] + " **")
.setDescription(ancArgs[1])
.setTimestamp()
.setThumbnail(servericon)
.setFooter(message.author.tag + " | Peace Keeper", message.author.displayAvatarURL({dynamic: true, size: 1024}))
message.channel.send(ancEmbed);
})
} else {
message.delete().catch();
const ancErrEmbed = new Discord.MessageEmbed()
.setColor('FF6961')
.setTitle("**error!**")
.setDescription("use the correct format: !special-anc <title> | <message>")
.setTimestamp()
.setFooter(message.author.tag + " | Peace Keeper", message.author.displayAvatarURL({dynamic: true, size: 1024}))
message.reply(ancErrEmbed).then(msg => msg.delete({timeout: 10000}));
}
}
module.exports.help = {
name: "special-anc"
}
【问题讨论】:
-
Discord.js 版本 12
-
我忘了说错误信息对不起:
commandFiles.run(bot, message, args); ^ ReferenceError: message is not defined at Object.<anonymous> (C:\Users\amral\Google Drive\Jordan-Discord-Bot\index.js:10:25)
标签: discord.js