我正在使用机器人内部的票务系统。我想要:-ticket new
或-ticket close
。但是我需要知道如何对这些命令做出两种不同的反应。因此,当玩家输入-ticket new <subject>
时,它将打开一个新的票证,并在我的日志记录通道中发送一条记录消息,指出该票证的主题并提及我的支持团队角色。或者,当玩家键入-ticket close <subject>
时,它将关闭现有故障单并在我的日志记录通道中发送一条记录消息,指出故障单的主题。
我尝试过
exports.run(client, message, arg1, arg2, subject) => {
if (args.slice(1).join(''))
或
exports.run(client, message, arg1, arg2, subject) => {
if (args[1] === '')
我当前的代码
exports.run = (client, message, arg1, arg2, subject) => {
let error = new Discord.RichEmbed()
.setColor("RED")
.setFooter("NebulaCraft")
.setTimestamp()
.setDescription("An error accoured please try again. If this reacours please contact support.")
if (args.slice(1).join("new")) {
let new1 = new Discord.RichEmbed()
.setColor("GREEN")
.setFooter("NebulaCraft")
.setTimestamp()
.setTitle('New Ticket')
.addField('Author', message.author)
.addField('Subject', `${subject}`)
client.channels.get('539852428565282851').send(new1).catch(console.error)
return (message.channel.send(error).catch(console.error))
}
if (args.slice(1).join("close")) {
let close1 = new Discord.RichEmbed()
.setColor("GREEN")
.setFooter("NebulaCraft")
.setTimestamp()
.setTitle('Ticket Closed')
.addField('Closed By', message.author)
.addField('Subject', `${subject}`)
client.channels.get('539852428565282851').send(close1).catch(console.error)
return (message.channel.send(error).catch(console.error))
}
}
我希望获得一个仅为单个arg创建2个选项的代码。我希望它为2个选项发送2条不同的消息。
答案 0 :(得分:1)
保持出口exports.run(client, message, args) =>
之前的状态
最终代码应为:
exports.run = (client, message, args) => {
let error = new Discord.RichEmbed()
.setColor("RED")
.setFooter("NebulaCraft")
.setTimestamp()
.setDescription("An error accoured please try again. If this reacours please contact support.")
if (args[0] === 'new') {
let new1 = new Discord.RichEmbed()
.setColor("GREEN")
.setFooter("NebulaCraft")
.setTimestamp()
.setTitle('New Ticket')
.addField('Author', message.author)
.addField('Subject', args.slice(1).join(' '))
client.channels.get('539852428565282851').send(new1).catch(console.error)
return (message.channel.send(error).catch(console.error))
}
if (args[0] === 'close') {
let close1 = new Discord.RichEmbed()
.setColor("GREEN")
.setFooter("NebulaCraft")
.setTimestamp()
.setTitle('Ticket Closed')
.addField('Closed By', message.author)
.addField('Subject', args.slice(1).join(' '))
client.channels.get('539852428565282851').send(close1).catch(console.error)
return (message.channel.send(error).catch(console.error))
}
}
答案 1 :(得分:0)
if (args[0] === 'option1') {
// Command specific here
} else if (args[0] === 'option2') {
// Command specific here
} else if (args[0] === 'option3') {
// Command specific here
} else {
// If none of the options match
// Command error specific here
}
这很好用!