我有我的主 Index.js 文件,里面有这段代码(想象输入是!help)
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
client.commands = new Discord.Collection();
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);
}
client.on("error", console.error);
client.once('ready', () => {
console.log('ProBot is online!');
});
client.on('message', message => {
if (message.author.bot) return;
if (message.guild === null) return;
if (message.content.startsWith("!")){
const prefix = "!";
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command.length === 0) return;
let cmd = client.commands.get(command);
if (!cmd) return message.reply(`\`${prefix + command}\` doesn't exist!`);
cmd.execute(message, args);
}
};
然后打开文件help.js,示例是
const Discord = require('discord.js');
module.exports = {
name: 'help',
description: "!help Command",
execute(message, args){
if(!message.member.hasPermission("MANAGE_GUILD")){ //Regular Output
message.react('❤️')
const help2Embed = new Discord.MessageEmbed()
.setColor('#ffd6d6')
.setTitle('!Help\n')
.setDescription('Check Your Private Messages For More Information')
message.channel.send(help2Embed)
const h11elpEmbed = new Discord.MessageEmbed()
.setColor('#ffd6d6')
.setTitle('!Help\n')
}
}}
问题是,如果它被更改为 !warn @member [low, med, high] [reason] - 索引能否将其放入 warn.js 文件,然后从那里根据 args[2] 是否低, med,高打开并执行一个新文件?为每个运行不同的代码。[或者如果有我忽略的更简单的方法]
慕仙森
相关分类