Files
discordeno/helpers/webhooks/getWebhooks.ts
Skillz4Killz 3a5bdce32d feat: helpers support strings in args (#2478)
* fix: helpers support strings in args

* fix: fmt
2022-09-15 20:59:02 -05:00

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 the list of webhooks for a guild.
*
* @param bot - The bot instance to use to make the request.
* @param guildId - The ID of the guild to get the list of webhooks for.
* @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-guild-webhooks}
*/
export async function getWebhooks(bot: Bot, guildId: BigString): Promise<Collection<bigint, Webhook>> {
const results = await bot.rest.runMethod<DiscordWebhook[]>(
bot.rest,
"GET",
bot.constants.routes.GUILD_WEBHOOKS(guildId),
);
return new Collection(
results.map((result) => {
const webhook = bot.transformers.webhook(bot, result);
return [webhook.id, webhook];
}),
);
}