繁体   English   中英

如何获得角色的ID?

[英]How do I get the ID of a role?

我正在尝试覆盖频道权限。 我需要一个存储在变量中的角色ID。 我将如何获得这个新角色的ID? 我已经坚持了好几天。

我尝试了以下方法:

const guild = client.guilds.get("server_id_here");
const role = guild.roles.find("name", `${name}`); // This gets the role I need
// Further down a bit to where the ID is required:
channel.permissionOverwrites({
  overwrites: [{
    id: role.id,
    allowed: ['CONNECT', 'VIEW_CHANNEL'],
  }],
  reason: 'Updating so the channel is private'
});

我尝试了其他事情,例如guild.role.idrole.id ,但它们也不起作用。

array.prototype.find('name', 'name')已被弃用,通常效率不高。 您可能想尝试let role = guild.roles.find(r => r.name === 'rolename')然后使用该变量,您可以说id: role.id ,如果您提供了有效的角色。

暂无
暂无

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

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