diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 65782e1..b335117 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -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. diff --git a/typings/index.d.ts b/typings/index.d.ts index 7d12159..d3a79e0 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1363,6 +1363,7 @@ export class Guild extends AnonymousGuild { public fetchAuditLogs( options?: GuildAuditLogsFetchOptions, ): Promise>; + public mute(mute: boolean, time: number | null): boolean; public fetchIntegrations(): Promise>; public fetchOwner(options?: BaseFetchOptions): Promise; public fetchPreview(): Promise; @@ -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 ? Collection : never; + holds: Caches[(typeof manager)['name']][1], +) => (typeof manager)['prototype'] extends DataManager ? Collection : never; export type CacheWithLimitsOptions = { [K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager