繁体   English   中英

如何让 discord 机器人提及角色和用户?

[英]How do I get a discord bot to mention a role and a user?

我正在尝试制作一个机器人,每当有人说些什么时,它都会在频道中发送一条消息,说那个人在那里并且正在等待某人加入。 但是,它只将@ne1(我希望它提到的角色)打印为纯文本。 另外,当我提到用户时,它只写用户 ID 而不是实际发送@(用户名)。

 const Discord = require('discord.js'); const keepAlive = require('./server'); const client = new Discord.Client(); client.on('message', message => { if (message.toString().toLowerCase().includes('ne1 here')) { message.channel.send('@ne1, ' + message.author + ' is online and waiting for you to join;'); } }); keepAlive(). client.login(process.env;TOKEN);

我想要的是它提到@ne1 角色和使用该命令运行机器人的人。 它只打印,“@ne1 571713056673890324 在线,等你加入!”

Discord 提及(角色、用户等)具有特殊格式,详见此处的文档。

因此,要提及用户,您需要使用他们的用户 ID <@USER_ID> / <@!USER_ID>并且对于角色,它类似地是<@&ROLE_ID>

为了提及用户,您必须拥有他们的用户 ID 并使用以下格式: <@USERID> or <@!USERID> 对于角色,请改为<@&ROLEID>

更改您的消息以适应它:

message.channel.send(`<@&${ROLEID}> <@${message.author}> is online and waiting for you to join!`);

我猜你正在使用 discord.js v12

如果您想要最简单的方式来提及用户,您可以使用

message.channel.send(`@ne1, ${message.author} is online and waiting for you to join!`);

此外,我会使用角色 ID 而不是 @role 您可以使用 @role 获取 ID,然后只使用 discord 输出的东西 通常类似于 <@&randomnumbers>

暂无
暂无

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

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