From e74aa7f6b0fe04e3473fc4a62a73a7db87307685 Mon Sep 17 00:00:00 2001 From: Idris <78701338+Idris1401@users.noreply.github.com> Date: Sat, 19 Nov 2022 21:54:43 +0100 Subject: [PATCH] feat(ThreadChannel): add a helper for pin and unpin (#8786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(ThreadChannel): add a helper for pin and unpin * fix: remove erros * Update packages/discord.js/src/structures/ThreadChannel.js Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Update packages/discord.js/src/structures/ThreadChannel.js Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Update packages/discord.js/src/structures/ThreadChannel.js Co-authored-by: Almeida * Update packages/discord.js/src/structures/ThreadChannel.js Co-authored-by: Almeida * Update packages/discord.js/typings/index.d.ts Co-authored-by: Aura Román * docs(ThreadChannel): improve description * types(ThreadChannel): fix types Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Almeida Co-authored-by: Aura Román Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/structures/ThreadChannel.js | 20 ++++++++++++++++++- packages/discord.js/typings/index.d.ts | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/ThreadChannel.js b/packages/discord.js/src/structures/ThreadChannel.js index ea10d1f8781c..dc135560f67c 100644 --- a/packages/discord.js/src/structures/ThreadChannel.js +++ b/packages/discord.js/src/structures/ThreadChannel.js @@ -1,6 +1,6 @@ 'use strict'; -const { ChannelType, PermissionFlagsBits, Routes } = require('discord-api-types/v10'); +const { ChannelType, PermissionFlagsBits, Routes, ChannelFlags } = require('discord-api-types/v10'); const { BaseChannel } = require('./BaseChannel'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); const { DiscordjsRangeError, ErrorCodes } = require('../errors'); @@ -457,6 +457,24 @@ class ThreadChannel extends BaseChannel { return this.edit({ appliedTags, reason }); } + /** + * Pins this thread from the forum channel (only applicable to forum threads). + * @param {string} [reason] Reason for pinning + * @returns {Promise} + */ + pin(reason) { + return this.edit({ flags: this.flags.add(ChannelFlags.Pinned), reason }); + } + + /** + * Unpins this thread from the forum channel (only applicable to forum threads). + * @param {string} [reason] Reason for unpinning + * @returns {Promise} + */ + unpin(reason) { + return this.edit({ flags: this.flags.remove(ChannelFlags.Pinned), reason }); + } + /** * Whether the client user is a member of the thread. * @type {boolean} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 437db959f4d5..542f29fc769a 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2816,7 +2816,10 @@ export class ThreadChannel extends TextBasedCha public setInvitable(invitable?: boolean, reason?: string): Promise; public setLocked(locked?: boolean, reason?: string): Promise; public setName(name: string, reason?: string): Promise; + // The following 3 methods can only be run on forum threads. public setAppliedTags(appliedTags: Snowflake[], reason?: string): Promise>; + public pin(reason?: string): Promise>; + public unpin(reason?: string): Promise>; public toString(): ChannelMention; }