Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Message#bulkDeletable #8760

Merged
merged 9 commits into from Nov 6, 2022
Merged
18 changes: 18 additions & 0 deletions packages/discord.js/src/structures/Message.js
Expand Up @@ -611,6 +611,24 @@ class Message extends Base {
);
}

/**
* Whether the message is bulk deletable by the client user
* @type {boolean}
* @readonly
* @example
* // Filter for bulk deletable messages
* channel.bulkDelete(messages.filter(message => message.bulkDeletable));
*/
get bulkDeletable() {
const permissions = this.channel?.permissionsFor(this.client.user);
return (
this.deletable &&
this.inGuild() &&
permissions.has(PermissionFlagsBits.ManageMessages) &&
Syjalo marked this conversation as resolved.
Show resolved Hide resolved
Syjalo marked this conversation as resolved.
Show resolved Hide resolved
Date.now() - this.createdTimestamp < 1_209_600_000
);
}

/**
* Whether the message is pinnable by the client user
* @type {boolean}
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -1692,6 +1692,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
public applicationId: Snowflake | null;
public attachments: Collection<Snowflake, Attachment>;
public author: User;
public get bulkDeletable(): boolean;
public get channel(): If<InGuild, GuildTextBasedChannel, TextBasedChannel>;
public channelId: Snowflake;
public get cleanContent(): string;
Expand Down