mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat(TextChannel): RateLimitPerUser (#2811)
* feat: Add TextChannel#rateLimitPerUser Rename parameter in TextChannel#setRateLimitPerUser feat: Add `rateLimitPerUser` param to ChannelData fix: eslint * docs: Updated typings * fix: Requested changes * fix: rateLimitPerUser being undefined when 0 When `rate_limit_per_user` is 0, the gateway does not send it (but REST does). When this is set to a non-zero number, this property starts to exist. Otherwise this will be `0`. Adding `|| 0` should do the trick changing `undefined` to `0`. * fix: eslint
This commit is contained in:
@@ -286,6 +286,7 @@ class GuildChannel extends Channel {
|
|||||||
* Lock the permissions of the channel to what the parent's permissions are
|
* Lock the permissions of the channel to what the parent's permissions are
|
||||||
* @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites]
|
* @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites]
|
||||||
* Permission overwrites for the channel
|
* Permission overwrites for the channel
|
||||||
|
* @property {number} [rateLimitPerUser] The ratelimit per user for the channel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -323,6 +324,7 @@ class GuildChannel extends Channel {
|
|||||||
user_limit: typeof data.userLimit !== 'undefined' ? data.userLimit : this.userLimit,
|
user_limit: typeof data.userLimit !== 'undefined' ? data.userLimit : this.userLimit,
|
||||||
parent_id: data.parentID,
|
parent_id: data.parentID,
|
||||||
lock_permissions: data.lockPermissions,
|
lock_permissions: data.lockPermissions,
|
||||||
|
rate_limit_per_user: data.rateLimitPerUser,
|
||||||
permission_overwrites,
|
permission_overwrites,
|
||||||
},
|
},
|
||||||
reason,
|
reason,
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ class TextChannel extends GuildChannel {
|
|||||||
*/
|
*/
|
||||||
this.lastMessageID = data.last_message_id;
|
this.lastMessageID = data.last_message_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ratelimit per user for this channel
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.rateLimitPerUser = data.rate_limit_per_user || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The timestamp when the last pinned message was pinned, if there was one
|
* The timestamp when the last pinned message was pinned, if there was one
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
@@ -52,6 +58,16 @@ class TextChannel extends GuildChannel {
|
|||||||
if (data.messages) for (const message of data.messages) this.messages.add(message);
|
if (data.messages) for (const message of data.messages) this.messages.add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<TextChannel>}
|
||||||
|
*/
|
||||||
|
setRateLimitPerUser(rateLimitPerUser, reason) {
|
||||||
|
return this.edit({ rateLimitPerUser }, reason);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether this channel is flagged as NSFW.
|
* Sets whether this channel is flagged as NSFW.
|
||||||
* @param {boolean} nsfw Whether the channel should be considered NSFW
|
* @param {boolean} nsfw Whether the channel should be considered NSFW
|
||||||
|
|||||||
3
typings/index.d.ts
vendored
3
typings/index.d.ts
vendored
@@ -1045,9 +1045,11 @@ declare module 'discord.js' {
|
|||||||
public readonly members: Collection<Snowflake, GuildMember>;
|
public readonly members: Collection<Snowflake, GuildMember>;
|
||||||
public messages: MessageStore;
|
public messages: MessageStore;
|
||||||
public nsfw: boolean;
|
public nsfw: boolean;
|
||||||
|
public rateLimitPerUser: number;
|
||||||
public topic: string;
|
public topic: string;
|
||||||
public createWebhook(name: string, options?: { avatar?: BufferResolvable | Base64Resolvable, reason?: string }): Promise<Webhook>;
|
public createWebhook(name: string, options?: { avatar?: BufferResolvable | Base64Resolvable, reason?: string }): Promise<Webhook>;
|
||||||
public setNSFW(nsfw: boolean, reason?: string): Promise<TextChannel>;
|
public setNSFW(nsfw: boolean, reason?: string): Promise<TextChannel>;
|
||||||
|
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<TextChannel>;
|
||||||
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1529,6 +1531,7 @@ declare module 'discord.js' {
|
|||||||
bitrate?: number;
|
bitrate?: number;
|
||||||
userLimit?: number;
|
userLimit?: number;
|
||||||
parentID?: Snowflake;
|
parentID?: Snowflake;
|
||||||
|
rateLimitPerUser?: number;
|
||||||
lockPermissions?: boolean;
|
lockPermissions?: boolean;
|
||||||
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user