[英]Javascript discord bot mention user midsentence
試圖讓機器人吐出隨機的場景消息,其中也包含@user 中句。
var myArray = [
message.author + " challenges the producers, but fails to survive a single puppet",
"Oh no, " + message.author + " got demolished by **Mr. Smiles**",
"After gearing up in several events " + message.author + " tried to swim and drowned"
]
var rand = myArray[Math.floor(Math.random() * myArray.length)];
channel.message(rand)
該命令正在鏈接到此腳本並且到目前為止有效,盡管它沒有提及執行命令的用戶,而是打印“未定義”。
我對 javascript 還很陌生,但如果您需要更多信息,請告訴我
message.author
是一個對象。 如果你想得到他的名字做message.author.username
如果你想提到他做: "<@" + message.author.id + ">"
嘗試這樣做:
const userAuthor = message.author.toString()
然后當你去編碼你的命令時:
message.channel.send(`The person, ${userAuthor}, is the coolest person.`)
您可能希望將message.author放入變量中:
let userVar = message.author
然后,您可以執行以下操作:
"Oh no," + "@" + userVar + " got demolished by **Mr. Smiles**"
但是正如seblor在他的評論中所說,您需要定義message
和channel
。 至於Arraybot,我不知道這是什么,但是您需要先解決此問題,然后才能嘗試我的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.