Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何对用户需求进行嵌入?_Javascript_Discord_Discord.js - Fatal编程技术网

Javascript 如何对用户需求进行嵌入?

Javascript 如何对用户需求进行嵌入?,javascript,discord,discord.js,Javascript,Discord,Discord.js,所以我正在编写一个discord机器人,想知道我该怎么做 如果用户输入 ~embed Title Description Colour 它将输出一个包含需求的嵌入 我该怎么做 谢谢你,安德烈 下面是我的代码:一种方法是使用一个字符,用户需要使用该字符来分隔字段。比如|或。用户通常不会在消息中键入的内容。 然后您可以使用该字符拆分消息 var arguments = myString.split('|'); 然后验证用户是否提供了所需的所有参数: if(arguments &&

所以我正在编写一个discord机器人,想知道我该怎么做

如果用户输入

~embed Title Description Colour
它将输出一个包含需求的嵌入

我该怎么做

谢谢你,安德烈


下面是我的代码:

一种方法是使用一个字符,用户需要使用该字符来分隔字段。比如
|
。用户通常不会在消息中键入的内容。
然后您可以使用该字符拆分消息

var arguments = myString.split('|');
然后验证用户是否提供了所需的所有参数:

if(arguments && arguments.length == 3){
    // keep going
} else {
    // warn the user that the syntax is wrong
}
最后,您需要生成嵌入

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

我在使用案例:顺便说一句,break方法!还是没人回答!答案已经有了。不要期望我们为您制作所有代码,所以您所要做的就是复制和粘贴。这样你就永远学不到了。是的,但是,你没有解释myStringI,它的okIt是‘var arguments=myString.split(‘‘)’)^ReferenceError:myString未定义“那么您需要更改myString,以了解您从我在上所做的消息中收到的内容。”。“case”嵌入的时刻:var arguments=myString.split(“|”);if(arguments&&arguments.length==3){}else{message.channel.send(“请完成参数。格式:Title | Description | color”)}var embed=new Discord.richebed(数据);embed.setTitle(参数[0]);embed.setDescription(参数[1]);setColor(参数[2]);中断`我还注意到一个错误,在
新Discord.RichEmbed()上,您没有
数据
。此外,我还更新了我的答案。您基本上需要获取
message.contents中的内容,并删除前缀和命令