Skip to content

Commit

Permalink
Add getRole method
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Aug 14, 2024
1 parent be511b8 commit 27ad9b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/routes/Guilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,21 @@ export default class Guilds {
}).then(data => data.pruned);
}

/**
* Get a role in a guild.
* @param guildID The ID of the guild.
* @param roleID The ID of the role to get.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#roles | Guild#roles}
*/
async getRole(guildID: string, roleID: string): Promise<Role> {
const guild = this._manager.client.guilds.get(guildID);
return this._manager.authRequest<RawRole>({
method: "GET",
path: Routes.GUILD_ROLE(guildID, roleID)
}).then(data => guild?.roles.update(data, guildID) ?? new Role(data, this._manager.client, guildID));
}

/**
* Get the roles in a guild.
* @param guildID The ID of the guild.
Expand Down
8 changes: 8 additions & 0 deletions lib/structures/Guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,14 @@ export default class Guild extends Base {
return this.client.rest.guilds.getPruneCount(this.id, options);
}

/**
* Get a role in this guild. Only use this if you need to. See the `roles` collection.
* @param roleID The ID of the role to get.
*/
async getRole(roleID: string): Promise<Role> {
return this.client.rest.guilds.getRole(this.id, roleID);
}

/**
* Get the roles in this guild. Only use this if you need to. See the `roles` collection.
*/
Expand Down

0 comments on commit 27ad9b0

Please sign in to comment.