首页 > 解决方案 > 当角色仍然可用时,Discord 会显示 @deleted-role

问题描述

当我用 discord.js 编写的不和谐机器人显示一个角色时,我遇到了这个问题@deleted-role,角色本身仍然可用,但机器人说已删除角色。我试图用另一个角色来测试它,这里是图像和代码:

if (message.content.includes("test"))
  return message.channel.send("<@&" + 855179067388461076 + "> why is that ");

结果

在此处输入图像描述

角色

在此处输入图像描述

你们能帮我解决这个问题吗?

标签: javascriptnode.jsdiscorddiscord.js

解决方案


问题是您使用整数 ( 855179067388461076) 作为雪花。它应该是一个字符串。由于这个数字大于 53 位 ( MAX_SAFE_INTEGER),JavaScript 很难解释它。它只能安全​​地表示 -(2 53 - 1) 和 2 53 - 1 之间的整数。

最大安全整数 9007199254740992
你的整数 855179067388461076
你的整数变成 855179067388461000

并且没有 ID 为 的角色855179067388461000。要解决此问题,请确保仅将字符串用作雪花:

message.channel.send("<@&" + "855179067388461076" + "> why is that")

// OR
const roleId = "855179067388461076"
message.channel.send("<@&" + roleId + "> why is that")

console.log('<@&' + 855179067388461076 + '> why is that ')
// => <@&855179067388461000> why is that 


推荐阅读