feat(guild): mute guild

This commit is contained in:
Yellowy 2023-01-07 15:06:28 -07:00
parent 93c230150c
commit 79942b987e
2 changed files with 32 additions and 2 deletions

View File

@ -638,6 +638,35 @@ class Guild extends AnonymousGuild {
}
}
/**
* Mute a guild
* @param {boolean} mute Weather or not you want to mute the guild
* @param {?number} time The amount of time you want to mute the server for in seconds
* @returns {boolean} true if it worked and false if it didn't
* @example
* guild.mute(true, 3600) // mutes the guild for an hour
* guild.mute(true, -1) // mutes the guild forever
* guild.mute(false); // unmutes the guild
*/
async mute(mute, time) {
try {
if (mute && time == null) return false;
if (time == null && !mute) await this.client.api.guilds(this.id).settings.patch({ muted: false });
let ms = time * 1000;
let date = new Date(Date.now() + ms).toISOString();
await this.client.api.guilds(this.id).settings.patch({
mute_config: {
end_time: date,
selected_time_window: time,
},
muted: true,
});
return true;
} catch (e) {
return false;
}
}
/**
* Fetches a collection of integrations to this guild.
* Resolves with a collection mapping integrations by their ids.

5
typings/index.d.ts vendored
View File

@ -1363,6 +1363,7 @@ export class Guild extends AnonymousGuild {
public fetchAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'>(
options?: GuildAuditLogsFetchOptions<T>,
): Promise<GuildAuditLogs<T>>;
public mute(mute: boolean, time: number | null): boolean;
public fetchIntegrations(): Promise<Collection<Snowflake | string, Integration>>;
public fetchOwner(options?: BaseFetchOptions): Promise<GuildMember>;
public fetchPreview(): Promise<GuildPreview>;
@ -5249,8 +5250,8 @@ export type CacheConstructors = {
// Narrowing the type of `manager.name` doesn't propagate type information to `holds` and the return type.
export type CacheFactory = (
manager: CacheConstructors[keyof Caches],
holds: Caches[typeof manager['name']][1],
) => typeof manager['prototype'] extends DataManager<infer K, infer V, any> ? Collection<K, V> : never;
holds: Caches[(typeof manager)['name']][1],
) => (typeof manager)['prototype'] extends DataManager<infer K, infer V, any> ? Collection<K, V> : never;
export type CacheWithLimitsOptions = {
[K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager<infer K, infer V, any>