本文介紹了如何嵌入用戶需求?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
所以我正在編寫一個不和諧的機器人并想知道我將如何做到這一點
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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!