我有我的主 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 文件,然后從那里根據(jù) args[2] 是否低, med,高打開并執(zhí)行一個新文件?為每個運行不同的代碼。[或者如果有我忽略的更簡單的方法]
Discord.js 我可以在另一個文件中執(zhí)行一個文件嗎
倚天杖
2023-07-14 15:42:48