Javascript discord bot 提到用户中间句子

Javascript discord bot mention user midsentence

试图让机器人吐出随机场景消息,其中还包括@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)

该命令链接到此脚本并且到目前为止有效,尽管它没有提及执行命令的用户,而是打印 "undefined".

我是 javascript 的新手,但如果您需要更多信息,请告诉我

message.author 是一个对象。如果你想知道他的名字,就做 message.author.username 如果您想提及他,请执行以下操作:"<@" + message.author.id + ">"

尝试这样做:

const userAuthor = message.author.toString()

然后当您编写命令时:

message.channel.send(`The person, ${userAuthor}, is the coolest person.`)