亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.js 我可以在另一個文件中執行一個文件嗎

Discord.js 我可以在另一個文件中執行一個文件嗎

倚天杖 2023-07-14 15:42:48
我有我的主 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,高打開并執行一個新文件?為每個運行不同的代碼。[或者如果有我忽略的更簡單的方法]
查看完整描述

1 回答

?
慕仙森

TA貢獻1827條經驗 獲得超8個贊

只是為了結束問題并得到答案。

來自 @worthy Alpaca 的非常有用的評論(全部歸功于他們) you can just create a new file, that you can name however you want, according to the schema you already have. Inside that file you can then handle whatever parameters you wish to use with that command


查看完整回答
反對 回復 2023-07-14
  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號