fix: guild edit

This commit is contained in:
Marcos Susaña 2024-07-09 18:15:53 -04:00
parent 6b931e5661
commit 02f08c5bff
No known key found for this signature in database
2 changed files with 20 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import type {
RESTPatchAPIAutoModerationRuleJSONBody, RESTPatchAPIAutoModerationRuleJSONBody,
RESTPatchAPIChannelJSONBody, RESTPatchAPIChannelJSONBody,
RESTPatchAPIGuildChannelPositionsJSONBody, RESTPatchAPIGuildChannelPositionsJSONBody,
RESTPatchAPIGuildJSONBody,
RESTPatchAPIGuildStickerJSONBody, RESTPatchAPIGuildStickerJSONBody,
RESTPostAPIAutoModerationRuleJSONBody, RESTPostAPIAutoModerationRuleJSONBody,
RESTPostAPIGuildChannelJSONBody, RESTPostAPIGuildChannelJSONBody,
@ -12,7 +13,7 @@ import type {
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import { toSnakeCase, type ObjectToLower } from '..'; import { toSnakeCase, type ObjectToLower } from '..';
import { resolveFiles } from '../../builders'; import { resolveFiles } from '../../builders';
import { BaseChannel, GuildMember, type CreateStickerBodyRequest } from '../../structures'; import { BaseChannel, Guild, GuildMember, type CreateStickerBodyRequest } from '../../structures';
import channelFrom from '../../structures/channels'; import channelFrom from '../../structures/channels';
import { BaseShorter } from './base'; import { BaseShorter } from './base';
import { type GuildStructure, Transformers } from '../../client/transformers'; import { type GuildStructure, Transformers } from '../../client/transformers';
@ -65,6 +66,13 @@ export class GuildShorter extends BaseShorter {
return this.client.proxy.guilds(id).widget.get({ query }); return this.client.proxy.guilds(id).widget.get({ query });
} }
async edit(guildId: string, body: RESTPatchAPIGuildJSONBody, reason?: string) {
const guild = await this.client.proxy.guilds(guildId).patch({ body, reason });
if (!this.client.cache.hasGuildsIntent) await this.client.cache.guilds?.patch(guildId, guild);
return new Guild(this.client, guild);
}
list(query?: RESTGetAPICurrentUserGuildsQuery) { list(query?: RESTGetAPICurrentUserGuildsQuery) {
return this.client.proxy return this.client.proxy
.users('@me') .users('@me')
@ -110,7 +118,7 @@ export class GuildShorter extends BaseShorter {
} }
} }
channels = await this.client.proxy.guilds(guildId).channels.get(); channels = await this.client.proxy.guilds(guildId).channels.get();
await this.client.cache.channels?.set( await this.client.cache.channels?.patch(
channels.map<[string, APIChannel]>(x => [x.id, x]), channels.map<[string, APIChannel]>(x => [x.id, x]),
guildId, guildId,
); );

View File

@ -1,4 +1,9 @@
import type { APIGuild, APIPartialGuild, GatewayGuildCreateDispatchData } from 'discord-api-types/v10'; import type {
APIGuild,
APIPartialGuild,
GatewayGuildCreateDispatchData,
RESTPatchAPIGuildJSONBody,
} from 'discord-api-types/v10';
import type { UsingClient } from '../commands'; import type { UsingClient } from '../commands';
import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util'; import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util';
import { AutoModerationRule } from './AutoModerationRule'; import { AutoModerationRule } from './AutoModerationRule';
@ -77,6 +82,10 @@ export class Guild<State extends StructStates = 'api'> extends (BaseGuild as unk
channels = BaseChannel.allMethods({ client: this.client, guildId: this.id }); channels = BaseChannel.allMethods({ client: this.client, guildId: this.id });
emojis = GuildEmoji.methods({ client: this.client, guildId: this.id }); emojis = GuildEmoji.methods({ client: this.client, guildId: this.id });
bans = GuildBan.methods({ client: this.client, guildId: this.id }); bans = GuildBan.methods({ client: this.client, guildId: this.id });
edit(body: RESTPatchAPIGuildJSONBody, reason?: string) {
return this.client.guilds.edit(this.id, body, reason);
}
} }
/** Maximun custom guild emojis per level */ /** Maximun custom guild emojis per level */