From 1e858872292a680e76d971f9e9adce87447c614f Mon Sep 17 00:00:00 2001 From: Isabella Date: Wed, 3 Oct 2018 17:21:26 -0500 Subject: [PATCH] backport: rateLimitPerUser (#2874) --- src/client/rest/RESTMethods.js | 2 ++ src/structures/TextChannel.js | 16 ++++++++++++++++ typings/index.d.ts | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index 0919d1b40..cbfa661a4 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -331,6 +331,8 @@ class RESTMethods { data.parent_id = _data.parent; data.permission_overwrites = _data.permissionOverwrites ? resolvePermissions.call(this, _data.permissionOverwrites, channel.guild) : undefined; + data.rate_limit_per_user = typeof _data.rateLimitPerUser !== 'undefined' ? + _data.rateLimitPerUser : channel.rateLimitPerUser; return this.rest.makeRequest('patch', Endpoints.Channel(channel), true, data, undefined, reason).then(newData => this.client.actions.ChannelUpdate.handle(newData).updated ); diff --git a/src/structures/TextChannel.js b/src/structures/TextChannel.js index 20b9d4970..17ca3738c 100644 --- a/src/structures/TextChannel.js +++ b/src/structures/TextChannel.js @@ -36,6 +36,12 @@ class TextChannel extends GuildChannel { * @type {?Snowflake} */ this.lastMessageID = data.last_message_id; + + /** + * The ratelimit per user for this channel + * @type {number} + */ + this.rateLimitPerUser = data.rate_limit_per_user || 0; } /** @@ -97,6 +103,16 @@ class TextChannel extends GuildChannel { } } + /** + * Sets the rate limit per user for this channel. + * @param {number} rateLimitPerUser The new ratelimit + * @param {string} [reason] Reason for changing the channel's ratelimits + * @returns {Promise} + */ + setRateLimitPerUser(rateLimitPerUser, reason) { + return this.edit({ rateLimitPerUser }, reason); + } + // These are here only for documentation purposes - they are implemented by TextBasedChannel /* eslint-disable no-empty-function */ send() { } diff --git a/typings/index.d.ts b/typings/index.d.ts index 3e387b3df..de036372e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1201,6 +1201,7 @@ declare module 'discord.js' { public messages: Collection; public nsfw: boolean; public topic: string; + public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise; public createWebhook(name: string, avatar: BufferResolvable, reason?: string): Promise; public fetchWebhooks(): Promise>; public setNSFW(nsfw: boolean, reason: string): Promise; @@ -1619,6 +1620,7 @@ declare module 'discord.js' { nsfw?: boolean; bitrate?: number; userLimit?: number; + rateLimitPerUser?: number; }; type ChannelLogsQueryOptions = {