Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  95] [ 2]  / answers: 1 / hits: 9384  / 4 Years ago, fri, august 21, 2020, 12:00:00

I'm kinda new to bot developing, but I've made a command called &pat and I want it to work like this:
You do &pat @user and I want it to respond like this: @user-executing-the-command, you have successfully patted @user-mentioned-in-the-command. I've come up with this code so far and it works all well apart from pinging the patted person. I does ping them, but it shows @invalid-user, and idk how to fix that. My code:


var pattedone = message.mentions.members.first();

if(!pattedone) return message.reply('please mention the one who should be patted');

message.reply(`you have successfully patted ${pattedone}`);


Do you know how to fix that @invalid-user thing? Thanks. Here is screenshot of the bot's response


More From » discord.js

 Answers
2

According to the Discord.js Documentation



Discord uses a special syntax to embed mentions in a message. For user mentions it is the user's ID with <@ at the start and > at the end, like this: <@86890631690977280>



With this in mind. Simply change


message.reply(`you have successfully patted ${pattedone}`);

to this


message.reply(`you have successfully patted <@${pattedone.id}>`);

EDIT


You'll also need to update


var pattedone = message.mentions.members.first();

to


var pattedone = message.mentions.users.first();


[#2833] Wednesday, August 19, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
malkajillc

Total Points: 652
Total Questions: 107
Total Answers: 98

Location: Finland
Member since Sat, Nov 6, 2021
3 Years ago
malkajillc questions
Tue, Jun 29, 21, 00:00, 3 Years ago
Tue, Aug 11, 20, 00:00, 4 Years ago
Tue, Apr 14, 20, 00:00, 4 Years ago
;