mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
feat(NewsChannel): add support for following (#4805)
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const TextChannel = require('./TextChannel');
|
||||
const { Error } = require('../errors');
|
||||
|
||||
/**
|
||||
* Represents a guild news channel on Discord.
|
||||
@@ -13,6 +14,25 @@ class NewsChannel extends TextChannel {
|
||||
// News channels don't have a rate limit per user, remove it
|
||||
this.rateLimitPerUser = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the target to this channel's followers.
|
||||
* @param {GuildChannelResolvable} channel The channel where the webhook should be created
|
||||
* @param {string} [reason] Reason for creating the webhook
|
||||
* @returns {Promise<NewsChannel>}
|
||||
* @example
|
||||
* if (channel.type === 'news') {
|
||||
* channel.addFollower('222197033908436994', 'Important announcements')
|
||||
* .then(() => console.log('Added follower'))
|
||||
* .catch(console.error);
|
||||
* }
|
||||
*/
|
||||
async addFollower(channel, reason) {
|
||||
const channelID = this.guild.channels.resolveID(channel);
|
||||
if (!channelID) throw new Error('GUILD_CHANNEL_RESOLVE');
|
||||
await this.client.api.channels(this.id).followers.post({ data: { webhook_channel_id: channelID }, reason });
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NewsChannel;
|
||||
|
||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -1187,6 +1187,7 @@ declare module 'discord.js' {
|
||||
): Promise<Webhook>;
|
||||
public setNSFW(nsfw: boolean, reason?: string): Promise<NewsChannel>;
|
||||
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
||||
public addFollower(channel: GuildChannelResolvable, reason?: string): Promise<NewsChannel>;
|
||||
}
|
||||
|
||||
export class PartialGroupDMChannel extends Channel {
|
||||
|
||||
Reference in New Issue
Block a user