From b8fd3f65d964f080afb42dd37eb21a13c0d84f8f Mon Sep 17 00:00:00 2001 From: HarmoGlace Date: Sun, 1 Nov 2020 12:32:20 +0100 Subject: [PATCH] feat(Message): add crosspostable property (#4903) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Advaith Co-authored-by: Alex Hîncu --- src/structures/Message.js | 17 +++++++++++++++++ typings/index.d.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/structures/Message.js b/src/structures/Message.js index 1b4302df0..36c26f2df 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -425,6 +425,23 @@ class Message extends Base { ); } + /** + * Whether the message is crosspostable by the client user + * @type {boolean} + * @readonly + */ + get crosspostable() { + return ( + this.channel.type === 'news' && + !this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) && + this.type === 'DEFAULT' && + this.channel.viewable && + this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.SEND_MESSAGES) && + (this.author.id === this.client.user.id || + this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES)) + ); + } + /** * Options that can be passed into editMessage. * @typedef {Object} MessageEditOptions diff --git a/typings/index.d.ts b/typings/index.d.ts index 041039f9c..7322dc62f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3018,6 +3018,7 @@ declare module 'discord.js' { | 'attachments' | 'channel' | 'deletable' + | 'crosspostable' | 'editable' | 'mentions' | 'pinnable' @@ -3029,6 +3030,7 @@ declare module 'discord.js' { attachments: Message['attachments']; channel: Message['channel']; readonly deletable: boolean; + readonly crosspostable: boolean; readonly editable: boolean; readonly edits: Message['edits']; embeds: Message['embeds'];