如何嵌入用户需求?
- 作者: 首席鉴黄大师
- 来源: 51数据库
- 2022-10-21
问题描述
所以我正在编写一个不和谐的机器人并想知道我将如何做到这一点
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]);
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
