feat: fetch guild role

This commit is contained in:
MARCROCK22 2024-08-21 15:13:48 +00:00
parent 4f3d5548a9
commit 5b6cb6ece6
4 changed files with 27 additions and 0 deletions

View File

@ -34,6 +34,7 @@ import type {
RESTGetAPIGuildPruneCountResult, RESTGetAPIGuildPruneCountResult,
RESTGetAPIGuildQuery, RESTGetAPIGuildQuery,
RESTGetAPIGuildResult, RESTGetAPIGuildResult,
RESTGetAPIGuildRoleResult,
RESTGetAPIGuildRolesResult, RESTGetAPIGuildRolesResult,
RESTGetAPIGuildScheduledEventQuery, RESTGetAPIGuildScheduledEventQuery,
RESTGetAPIGuildScheduledEventResult, RESTGetAPIGuildScheduledEventResult,
@ -219,6 +220,7 @@ export interface GuildRoutes {
( (
id: string, id: string,
): { ): {
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildRoleResult>;
patch( patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildRoleJSONBody>, args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildRoleJSONBody>,
): Promise<RESTPatchAPIGuildRoleResult>; ): Promise<RESTPatchAPIGuildRoleResult>;

View File

@ -21,6 +21,22 @@ export class RoleShorter extends BaseShorter {
return Transformers.GuildRole(this.client, res, guildId); return Transformers.GuildRole(this.client, res, guildId);
} }
async fetch(guildId: string, roleId: string, force = false) {
const role = await this.raw(guildId, roleId, force);
return Transformers.GuildRole(this.client, role, guildId);
}
async raw(guildId: string, roleId: string, force = false) {
let role: APIRole | undefined;
if (!force) {
role = await this.client.cache.roles?.raw(roleId);
if (role) return role;
}
role = await this.client.proxy.guilds(guildId).roles(roleId).get();
await this.client.cache.roles?.set(roleId, guildId, role);
return role;
}
/** /**
* Retrieves a list of roles in the guild. * Retrieves a list of roles in the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.

View File

@ -27,6 +27,10 @@ export class GuildRole extends DiscordBase {
return this.client.guilds.fetch(this.guildId, force); return this.client.guilds.fetch(this.guildId, force);
} }
fetch(force = false) {
return this.client.roles.fetch(this.guildId, this.id, force);
}
edit(body: RESTPatchAPIGuildRoleJSONBody, reason?: string) { edit(body: RESTPatchAPIGuildRoleJSONBody, reason?: string) {
return this.client.roles.create(this.guildId, body, reason); return this.client.roles.create(this.guildId, body, reason);
} }

View File

@ -637,6 +637,11 @@ export interface RESTPostAPIGuildBulkBanResult {
*/ */
export type RESTGetAPIGuildRolesResult = APIRole[]; export type RESTGetAPIGuildRolesResult = APIRole[];
/**
* https://discord.com/developers/docs/resources/guild#get-guild-role
*/
export type RESTGetAPIGuildRoleResult = APIRole;
/** /**
* https://discord.com/developers/docs/resources/guild#create-guild-role * https://discord.com/developers/docs/resources/guild#create-guild-role
*/ */