所以我正在编写一个不和谐的机器人并想知道我将如何做到这一点
So I'm coding a discord bot and wondering how I would do this
如果用户输入
~embed Title Description Colour
它将输出一个包含需求的嵌入.
It will output an embed with the requirements.
我该怎么做?
感谢@André
这是我的代码:https://ghostbin.com/paste/uetpj
一种方法是使用用户需要用来分隔字段的字符.像 | 或 ;;.用户通常不会在消息中键入的内容.
然后您可以使用该字符拆分消息.
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
}
最后你需要生成嵌入.
var embed = new Discord.RichEmbed();
embed.setTitle(arguments[0]);
embed.setDescription(arguments[1]);
embed.setColor(arguments[2]);
这篇关于如何嵌入用户需求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
discord.js v12:我如何等待 DM 频道中的消息?discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
如何让我的机器人提及发出该机器人命令的人how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
如何修复必须使用导入来加载 ES 模块 discord.jsHow to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
如何列出来自特定服务器的所有成员?How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot:修复“找不到 FFMPEG"Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
使用 discord.js 加入 discord 服务器时的欢迎消息Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)