discord.js如何在命令之间传递args

时间:2020-06-26 04:17:06

标签: javascript node.js discord discord.js

我想转移args;尽管我不太确定如何执行此操作,但我尝试将它们作为全局变量。

带有args的命令:

let messageArray = message.content.split(" ");
const args = messageArray.slice(1);
    
    
const invite = await message.channel.createInvite();
if(cmd === `${prefix}order`) {

    if(!args) return message.reply("Please specify what you would like to order.");

        
    baseOrderNumber++;
    let order = args.join(" ");

    const orderEmbed = new Discord.MessageEmbed()
    orderIcon = "https://i.imgur.com/Le0Eist.png"
    orderEmbed.setTitle("New Order")
    orderEmbed.setColor("#FF2D00")
    orderEmbed.setThumbnail(orderIcon)
    orderEmbed.addField("Order Number", baseOrderNumber)
    orderEmbed.addField("Order", order)
    orderEmbed.addField("Customer", message.author)
    orderEmbed.addField("Server Invite", invite)

    bot.channels.cache.get('723838675489914891').send(orderEmbed)    
    let eekowo = fs.writeFileSync('orderAuthors.txt', message.author.tag, order); 
}

需要args的命令:

if(cmd === `${prefix}deliver`){
        let eekowo2 = fs.readFileSync('orderAuthors.txt', 'utf8')
        deliverEmbed = new Discord.MessageEmbed()
        deliverIcon = message.guild.iconURL
        deliverEmbed.addField("Invite", invite)
        deliverEmbed.addField("Customer", eekowo2)
        deliverEmbed.addField("Items", orderEmbed.order)
        message.author.send(deliverEmbed)
}

我该如何转移他们?

1 个答案:

答案 0 :(得分:1)

好吧,您可以将它们写入 json 文件中,并在需要时要求它们,只需执行以下操作即可:

// Your command with the args
if(args) { client.transferedArgs = args; }

// Deliver command
let oldArgs = client.transferedArgs;