javascript - How to make a bot ping a user using discord.js - Stack Overflow

I'm kinda new to bot developing, but I've made a mand called &pat and I want it to work l

I'm kinda new to bot developing, but I've made a mand 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-mand, you have successfully patted @user-mentioned-in-the-mand. I've e 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

I'm kinda new to bot developing, but I've made a mand 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-mand, you have successfully patted @user-mentioned-in-the-mand. I've e 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

Share asked Aug 21, 2020 at 14:40 PandiconPandicon 4303 gold badges17 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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();

you can mention a user with the following "method":

let mention = `<@${userId}>`;

Discord mentions work like this: <@user-id>. Simply replace user-id with the ID of the "victim". You can also mention roles using <&channel-id> or text channels using <#channel-id>.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744926208a4601451.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信