Javascript discord bot 提到用户中间的句子

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50948808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:20:50  来源:igfitidea点击:

Javascript discord bot mention user midsentence

javascriptdiscord.js

提问by Thiil

Trying to get the bot to spit out random scenario messages that also include @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)

The command is linking to this script and so far works, although instead of mentioning the user doing the command, it prints "undefined".

该命令正在链接到该脚本并且到目前为止有效,尽管它没有提及执行该命令的用户,而是打印“未定义”。

I'm fairly new to javascript, but let me know if you need more information

我对 javascript 还很陌生,但如果您需要更多信息,请告诉我

回答by Tomi Kordos

message.authoris an object. If you want to get his name do message.author.usernameIf you want to mention him do: "<@" + message.author.id + ">"

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