admin管理员组文章数量:1292244
Trying to get the bot to spit out random scenario messages that also include @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)
The mand is linking to this script and so far works, although instead of mentioning the user doing the mand, it prints "undefined".
I'm fairly new to javascript, but let me know if you need more information
Trying to get the bot to spit out random scenario messages that also include @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)
The mand is linking to this script and so far works, although instead of mentioning the user doing the mand, it prints "undefined".
I'm fairly new to javascript, but let me know if you need more information
Share edited May 23, 2020 at 10:07 m02ph3u5 3,1617 gold badges41 silver badges57 bronze badges asked Jun 20, 2018 at 12:56 ThiilThiil 971 gold badge3 silver badges11 bronze badges 9-
Use
toString()
to make a mention : discord.js/#/docs/main/stable/class/User?scrollTo=toString Though I think this will not solve your problem. I think we need a bit more of your code to be able to find the issue. – Seblor Commented Jun 20, 2018 at 13:02 - upon changing it to message.author.toString() i recieve the following error: Error [javax.script.ScriptException]: TypeError: Cannot read property "toString" from undefined in <eval> at line number 1 – Thiil Commented Jun 20, 2018 at 13:05
-
Of course it would print that error, since
message.author
is undefined,message.author.toString()
does not exists. That is why I edited my mend saying that we need more information – Seblor Commented Jun 20, 2018 at 13:08 - This IS the entire code ... For the mand in discord, i did //custom setvalue NAMEOFCOMMAND pastebin./hkB85kjp It could be that by making it grab off pastebin, that the message.author can't be grabbed? – Thiil Commented Jun 20, 2018 at 13:10
-
This cannot be the entire code, as you never defined
message
orchannel
. They must be ming from somewhere, like a function definition, in which case it would be nice to have its call. – Seblor Commented Jun 20, 2018 at 13:12
2 Answers
Reset to default 6message.author
is an object. If you want to get his name do message.author.username
If you want to mention him do: "<@" + message.author.id + ">"
Try to do this:
const userAuthor = message.author.toString()
And then when you go to code your mand:
message.channel.send(`The person, ${userAuthor}, is the coolest person.`)
本文标签: discordjsJavascript discord bot mention user midsentenceStack Overflow
版权声明:本文标题:discord.js - Javascript discord bot mention user midsentence - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741550320a2384842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论