fix(Message): unify guild method (#322)

* fix(Message): unify guild method

* fix(Message): guild method overloads
This commit is contained in:
veryCrunchy 2025-01-09 01:35:19 +01:00 committed by GitHub
parent 8bc6a345c5
commit 767d2a4302
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
import { type AllChannels, Embed } from '..';
import { type AllChannels, Embed, ReturnCache } from '..';
import type { ListenerOptions } from '../builders';
import {
type GuildMemberStructure,
@ -72,9 +72,19 @@ export class BaseMessage extends DiscordBase {
return Formatter.messageLink(this.guildId ?? '@me', this.channelId, this.id);
}
async guild(force = false): Promise<GuildStructure<'api'> | undefined> {
if (!this.guildId) return;
return this.client.guilds.fetch(this.guildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'> | undefined>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.guildId)
return (
mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve()
) as any;
switch (mode) {
case 'cache':
return this.client.cache.guilds?.get(this.guildId);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
channel(force = false): Promise<AllChannels> {