diff --git a/src/constants/discord.ts b/src/constants/discord.ts index ea2e01227..074fa2949 100644 --- a/src/constants/discord.ts +++ b/src/constants/discord.ts @@ -45,6 +45,10 @@ export const endpoints = { `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions`, CHANNEL_MESSAGE_REACTION: (id: string, messageID: string, emoji: string) => `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions/${emoji}`, + CHANNEL_FOLLOW: (id: string) => + `${baseEndpoints.BASE_URL}/channels/${id}/followers`, + CHANNEL_MESSAGE_CROSSPOST: (id: string, messageID: string) => + `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/crosspost`, // Guild Endpoints GUILD: (id: string) => `${GUILDS_BASE(id)}`, diff --git a/src/handlers/channel.ts b/src/handlers/channel.ts index 3873d6516..2bd7095d5 100644 --- a/src/handlers/channel.ts +++ b/src/handlers/channel.ts @@ -17,6 +17,7 @@ import { MessageContent, CreateInviteOptions, ChannelEditOptions, + FollowedChannelPayload, } from "../types/channel.ts"; import { logYellow } from "../utils/logger.ts"; @@ -340,3 +341,24 @@ export function editChannel(channel: Channel, options: ChannelEditOptions) { payload, ); } + +/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */ +export async function followChannel( + sourceChannelID: string, + targetChannelID: string, +) { + if ( + !botHasChannelPermissions(targetChannelID, [Permissions.MANAGE_WEBHOOKS]) + ) { + throw new Error(Errors.MISSING_MANAGE_CHANNELS); + } + + const data = await RequestManager.post( + endpoints.CHANNEL_FOLLOW(sourceChannelID), + { + webhook_channel_id: targetChannelID, + }, + ) as FollowedChannelPayload; + + return data.webhook_id; +} diff --git a/src/handlers/message.ts b/src/handlers/message.ts index 86b967f92..54a55a136 100644 --- a/src/handlers/message.ts +++ b/src/handlers/message.ts @@ -223,3 +223,11 @@ export async function editMessage( ); return createMessage(result as MessageCreateOptions); } + +export async function publishMessage(channelID: string, messageID: string) { + const data = await RequestManager.post( + endpoints.CHANNEL_MESSAGE_CROSSPOST(channelID, messageID), + ) as MessageCreateOptions; + + return createMessage(data); +} diff --git a/src/types/channel.ts b/src/types/channel.ts index f175fd9b0..a472fa8d2 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -146,3 +146,10 @@ export interface CreateInviteOptions { /** If true, don't try to reuse a similar invite (useful for creating many unique one time use invites.) */ unique: boolean; } + +export interface FollowedChannelPayload { + /** The source channel id */ + channel_id: string; + /** The webhook id */ + webhook_id: string; +}