How to make a embed to the user requirments?

2019-08-15 01:33发布

问题:

So I'm coding a discord bot and wondering how I would do this

If the user inputs

~embed Title Description Colour

It will output an embed with the requirements.

How would I do so?

And thanks @André

Heres my code : https://ghostbin.com/paste/uetpj

回答1:

One way to do it would be with a character that the user needs to use to separate the fields. Like | or ;;. Something the users wont usually type in the messages.
Then you can split the message with that character.

var arguments = myString.split('|');

And then verify if the user gave all the arguments required:

if(arguments && arguments.length == 3){
    // keep going
} else {
    // warn the user that the syntax is wrong
}

And finally you would need to generate the Embed.

var embed = new Discord.RichEmbed();
embed.setTitle(arguments[0]);
embed.setDescription(arguments[1]);
embed.setColor(arguments[2]);