从我的自定义 Discord 机器人中 Ping 自动消息中的角色

发布于 2025-01-18 12:27:37 字数 651 浏览 4 评论 0原文

我面临着关于我的Discord机器人的问题。 我做出了一个自动答案,可以在用户扮演角色时抚摸他。 一切正常,用户会被刺穿,并且嵌入按计划显示。

我想在此消息中添加角色ping。以下代码的问题在于,角色不会被刺穿(只是角色,用户名和嵌入式工作)。它只是显示了代码中的角色的ID。

有人可以告诉我,这行是否有错误:

channel.send({content :`**${oldMember.user} something is written here** <@&11111111111111>, something is written here too`, embeds :\[embed\]});

(1111111111 = rome ID)

我希望每次发送此消息时我的bot ping the wore。 我也尝试了提到的代码行,但这显示了“@dreated-lole”:

channel.send({content :`**${oldMember.user} something is written here** <@&${1111111111111}, something is written here too`, embeds :\[embed\]});

I'm facing an issue concerning my Discord bot.
I made an automatic answer that pings the user when he gets a role.
Everything works fine, the user gets pinged and the embed appears as planed.

I would like to add a role ping to this message. The problem with the following code is that the role won't get pinged (just the role, the username and the embed work perfectly). It just shows the ID of the role exactly like in the code.

Could someone tell me if there's an error in this line:

channel.send({content :`**${oldMember.user} something is written here** <@&11111111111111>, something is written here too`, embeds :\[embed\]});

(11111111111 = role ID)

I expect my bot to ping the role every time this message is sent.
I tried the mentioned code line and this one as well, but this shows "@deleted-role":

channel.send({content :`**${oldMember.user} something is written here** <@&${1111111111111}, something is written here too`, embeds :\[embed\]});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-01-25 12:27:37

经过一番研究,我找到了一个可行的代码:

const role = message.guild.roles.cache.filter(role => role.id === "11111111111111");

channel.send({content :`**${oldMember.user} something is written here** ${role}, something is written here too`, embeds :\[embed\]});

https:// Discord.js.org/#/docs/discord.js/stable/class/RoleManager Discord.js 文档作为资源非常有用。

After some researching, I found a workable code:

const role = message.guild.roles.cache.filter(role => role.id === "11111111111111");

channel.send({content :`**${oldMember.user} something is written here** ${role}, something is written here too`, embeds :\[embed\]});

https://discord.js.org/#/docs/discord.js/stable/class/RoleManager the Discord.js documentations are really helpful as a resource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文