Javascript Discord机器人提及用户中间句

时间:2018-06-20 12:56:28

标签: javascript discord.js

试图让机器人吐出还包括@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还是很陌生,但是如果您需要更多信息,请告诉我

3 个答案:

答案 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在他的评论中所说,您需要定义messagechannel。至于Arraybot,我不知道那是什么,但是您需要先解决此问题,然后才能尝试我的答案。