简体   繁体   English

如何仅使用用户 ID 提及使用 Discord.js 的人?

[英]How do I mention a person using Discord.js with only the user id?

I'm trying to build a bot which mentions people on discord. I already have the usernames of people, and I've been trying to mention users with this:我正在尝试构建一个在 discord 上提及人员的机器人。我已经有了人员的用户名,并且我一直在尝试通过以下方式提及用户:

function discordsend(usern)
{ 
string = "$add-money"+usern+"1";
const channel = client.channels.cache.get('channelid');
channel.send(string)
console.log(channel);
}

However, it just sends the message plainly to the channel without actually mentioning the user.但是,它只是将消息明明白白地发送到频道,而没有实际提及用户。 Is there any way I could mention a user just using their user id?有什么办法可以仅使用他们的用户 ID 来提及用户吗? (Username with Discriminator) (带鉴别器的用户名)

I've also heard I can mention users if I have their IDs, but I only have their User IDs.我还听说如果我有用户 ID 就可以提及用户,但我只有他们的用户 ID。 If there is a way to obtain IDs from UserIDs, please let me know !如果有办法从 UserID 获取 ID,请告诉我!

FYI, UserID is in the form user#discriminator仅供参考,UserID 的形式为 user#discriminator

Discord uses a special syntax to embed mentions in a message. Discord 使用特殊语法在消息中嵌入提及。 For user mentions, it is the user's ID with <@ at the start and > at the end, like this:对于用户提及,它是用户的 ID,开头为<@ ,结尾为> ,如下所示:

<@12345678912345678>

If they have a nickname, there will also be a !如果他们有昵称,也会有一个! after the @ .@之后。

If I read your question correctly, you wanted to mention a member using their ID only, to use their ID you need to cache.get :如果我没看错你的问题,你想提到一个只使用他们的 ID 的成员,要使用他们的 ID,你需要cache.get

const member = message.guild.members.cache.get(args[0])

if you're familiar with args functions then you can use it too with channels and roles如果您熟悉args函数,那么您也可以将它用于channelsroles

If you wanted to ping them in bot's messages.如果您想在机器人的消息中对它们执行 ping 操作。 you can use ${member} for example:你可以使用${member}例如:

message.channel.send(`${member}`)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM