kate
kate

Reputation: 11

how to take the second part of the message

I want to make a command like:

+channel [name] [category]

My code is all working, but I'm not sure how to take the [name] and the [category] as different variables- I used

args.join(" ")

So my bot takes everything I say after the prefix and command as the channel name. Thanks in advance and have a good day.

Upvotes: 0

Views: 36

Answers (1)

Joseph
Joseph

Reputation: 6259

if I understood correctly so you have a string as a command for example

+channel [name] [category]

so what you need is to parse it and get each part in a variable,

you could do something like this using split and destructuring

let command = '+channel test cat_test'
const [channel, name, category] = command.split(' ');

console.log(channel) // +channel
console.log(name) // test
console.log(category) // cat_test

Upvotes: 1

Related Questions