试图让机器人吐出还包括@user midsentence的随机场景消息。
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还是很陌生,但是如果您需要更多信息,请告诉我
答案 0 :(得分:0)
message.author
是一个对象。如果您想知道他的名字,请message.author.username
如果您想提及他,请执行:"<@" + message.author.id + ">"
答案 1 :(得分:0)
尝试这样做:
const userAuthor = message.author.toString()
然后当您编写命令时:
message.channel.send(`The person, ${userAuthor}, is the coolest person.`)
答案 2 :(得分:-1)
您希望将message.author放入变量:
let userVar = message.author
然后您可以执行以下操作:
"Oh no," + "@" + userVar + " got demolished by **Mr. Smiles**"
但是正如seblor在他的评论中所说,您需要定义message
和channel
。至于Arraybot,我不知道那是什么,但是您需要先解决此问题,然后才能尝试我的答案。