Thiil
Thiil

Reputation: 97

Javascript discord bot mention user midsentence

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 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

Upvotes: 2

Views: 17898

Answers (2)

Rohan Shah
Rohan Shah

Reputation: 1

Try to do this:

const userAuthor = message.author.toString()

And then when you go to code your command:

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

Upvotes: 0

Tomáš Kordoš
Tomáš Kordoš

Reputation: 333

message.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 + ">"

Upvotes: 6

Related Questions