mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 16:30:08 +00:00
* rename getWebhooks to getGuildWebhooks move getChannelWebhooks from `helpers/channels` to `helpers/webhooks` * helpers/webhooks: getWebhook -> getGuildWebhooks * tests: fix webhook test Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import type { Bot } from "../../bot.ts";
|
|
import { Webhook } from "../../transformers/webhook.ts";
|
|
import { DiscordWebhook } from "../../types/discord.ts";
|
|
import { BigString } from "../../types/shared.ts";
|
|
import { Collection } from "../../util/collection.ts";
|
|
|
|
/**
|
|
* Gets a list of webhooks for a channel.
|
|
*
|
|
* @param bot - The bot instance to use to make the request.
|
|
* @param channelId - The ID of the channel which to get the webhooks of.
|
|
* @returns A collection of {@link Webhook} objects assorted by webhook ID.
|
|
*
|
|
* @remarks
|
|
* Requires the `MANAGE_WEBHOOKS` permission.
|
|
*
|
|
* @see {@link https://discord.com/developers/docs/resources/webhook#get-channel-webhooks}
|
|
*/
|
|
export async function getChannelWebhooks(bot: Bot, channelId: BigString): Promise<Collection<bigint, Webhook>> {
|
|
const results = await bot.rest.runMethod<DiscordWebhook[]>(
|
|
bot.rest,
|
|
"GET",
|
|
bot.constants.routes.CHANNEL_WEBHOOKS(channelId),
|
|
);
|
|
|
|
return new Collection(
|
|
results.map((result) => {
|
|
const webhook = bot.transformers.webhook(bot, result);
|
|
return [webhook.id, webhook];
|
|
}),
|
|
);
|
|
}
|