Toby Royal
Toby Royal

Reputation: 3

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.

Upvotes: 0

Views: 197

Answers (1)

Jordan Gray
Jordan Gray

Reputation: 21

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.

Upvotes: 1

Related Questions