How to tag users?

孤者浪人 提交于 2019-12-13 09:55:43

问题


I am looking to create a command in order to tag certain users.

This is what I have tried:

var players = [
"@RYAN#9602"
]



switch(args[0].toLowerCase()){

 case "play":
            message.channel.send(players.join('\n'));
            break;
}

However, it just sends a message into the text channel without actually tagging the user.

In summmary, I am looking to be able to tag a user through a discord.js bot.

Any help would be greatly appreciated, thanks!


回答1:


You have two options.

You can either use the toString method on the User object, or form the mention yourself using the user's ID.

Here's an example using toString:

client.on("message", => {
    const channel = message.channel;
    channel.send(message.author.toString());
});

And here's an example using the ID

client.on("message", => {
    const channel = message.channel;
    channel.send("<@" + message.author.id + ">");
});


来源:https://stackoverflow.com/questions/47622930/how-to-tag-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!