简体   繁体   中英

How do I get the ID of a role?

I am trying to get a channel permissions overwrite. I need an ID of a role which is stored in a variable. How would I get the ID of this new role? I've been stuck on this for days.

I've tried the following:

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'
});

I've tried other things such as guild.role.id or role.id and they are not working either.

array.prototype.find('name', 'name') is deprecated and often isn't very efficient. You may want to try something like let role = guild.roles.find(r => r.name === 'rolename') then using that variable you can said id: role.id , were you to have provided a valid role.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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