rez
rez

Reputation: 331

Separate 2 arguments by comma

I am trying to make it when I type the command -announce This is a title, and this is a description How can I separate two arguments by a comma because the way I made it does not work

let invalidusage = new MessageEmbed()
.setColor("10F23D")
.setDescription('Koristi:\n``announce <title> <description>``')

let title = args[0];
let description = args.slice(0).join(" ");

const exampleEmbed = new MessageEmbed()
  .setColor('10F23D')
  .setTitle(title)
  .setDescription(description)

message.channel.send({ embeds: [exampleEmbed] });

With my code when I try to type -announce hello hello, this is alert (Hello hello should be title, and this is alert should be description) but my code just parses second hello to description

Upvotes: 0

Views: 291

Answers (1)

Static
Static

Reputation: 786

From what I understand, you are trying to separate two values by a comma. So A user could input "-announce a title, and a description"

You can achieve this by chaining all of your arguments back together, and splitting them by the first comma - any other commas after the first will be treated as part of the description. You can achieve this by doing:

const split = args.join(" ").split(",");
const title = split[0];
const description = split.slice(1).join(" ");

This will extract the title and description from the message arguments.

If you have any questions, do let me know in the comments below and I'll do my best to try and get back to you as soon as possible. In the mean time, here are the MDN web docs for <String>.split() and <Array>.join() which may help you understand what's going on here.

ATB!

Upvotes: 1

Related Questions