我需要将参数从一个命令传递到另一个命令。
我需要从以下命令转移args(命令)的命令:
const invite = await message.channel.createInvite()
if(cmd === `${prefix}order`){
if(!args) return message.reply("Please specify what you would like to order.")
console.log(args)
baseOrderNumber++;
var order = args.join(" ")
let 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);
}
我需要转移到的命令:
if(cmd === `${prefix}deliver`){
if(!args[1]) message.reply("Please provide an order number.")
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)
}
这可能吗?如果是这样;怎么样?
答案 0 :(得分:1)
您有两种选择:
我的建议是采用选项1,但看起来好像您没有使用命令处理程序,因此这是#2的可能应用:
// 1st command
const invite = await message.channel.createInvite()
if (cmd === `${prefix}order`) {
if (!args) return message.reply("Please specify what you would like to order.")
console.log(args)
baseOrderNumber++;
var order = args.join(" ")
let 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);
Deliver(message, Discord, args);
}
// 2nd command
if (cmd === `${prefix}deliver`) {
Deliver(message, Discord, args);
}
// In the global scope
function Deliver(message, embed, args) {
if (!args[1]) message.reply("Please provide an order number.")
// ^ If this is an error check, you may want to put return here, before the reply
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)
}
}