Reputation: 5
I am working on a ticket system inside my bot. I would like to have: -ticket new
or -ticket close
. But I need to know how to have 2 different reactions to these commands. So when a player types -ticket new <subject>
, it will open a new ticket send a logging message in my logging channel which states the subject of the ticket & mention my support team role. Or when a player types -ticket close <subject>
, it will close an existing ticket & send a logging message in my logging channel which states the subject of the ticket.
I have tried
exports.run(client, message, arg1, arg2, subject) => {
if (args.slice(1).join(''))
or
exports.run(client, message, arg1, arg2, subject) => {
if (args[1] === '')
My current code
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))
}
}
I expect to get a code that creates 2 options for a single arg only. I would like to have it send 2 different messages for the 2 options.
Upvotes: 0
Views: 287
Reputation: 5
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
}
This works perfectly fine!
Upvotes: 0
Reputation: 2785
Keep the exports like they were before exports.run(client, message, args) =>
The final code should be:
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))
}
}
Upvotes: 1