GreatGaja
GreatGaja

Reputation: 405

Sending a dm if a command was used alongside username using .js

Making a Discord bot that has a few commands to request login info to private servers. Some of these are given on a case to case basis. So currently the bot send me a dm when someone uses the !Ticket command. I would like to include the username of the person that used the command.

When using the ${messages.author} or ${user} it just show exactly that in the message not the actual user or author.

I am using the discord.js.org documentation but still new to this. There were a few strings I saw online but can't seem to figure out how to trace down string using the actual documentation.... I know it must sound silly,

I just want to know how does works. I'm guessing it needs to be something along the line of messages.author. and then print or show it somehow? If anybody can point me where to look on the docs for the string order it would be great.

I tried multiple functions that I used in previous command but most weren't as complex as this on I guess.

case 'ticket':
                    const user = bot.users.get('Id of the recipient/admin');
                    //var user = message.author;
                    user.send('Server info has been requested by <author?>');

return message. reply ('A request has been sent. info is handed out 
                        manually so it might take a bit if admins are 
                      offline')

I expect to receive a message saying "Server info has been requested by "

and the person using the command getting a @ message after the command was used, this last @ bit already works.

Upvotes: 1

Views: 84

Answers (2)

GreatGaja
GreatGaja

Reputation: 405

Thanks, this seems like a common thing. I used ' or " is that normal unless you want
to add other things like the user/author mention. Need to learn that I guess.

user.send(`Server info has been requested by ${user}`)

Still did not give the author in a dm but the receiver. I changed it to

user.send(`Server info has been requested by ${message.author}`);

Now it sends a DM to the role/people added to the user list with a name of the
person that issued the command.

Upvotes: 0

Cursed
Cursed

Reputation: 1003

You should use this ` not ' , the code was right. Like this:

user.send(`Server info has been requested by ${user}`)

Upvotes: 2

Related Questions