Files
discordeno/helpers/invites/getChannelInvites.ts
2022-02-11 09:49:53 +00:00

26 lines
744 B
TypeScript

import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts";
import { Collection } from "../../util/collection.ts";
import type { Bot } from "../../bot.ts";
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
export async function getChannelInvites(bot: Bot, channelId: bigint) {
const result = await bot.rest.runMethod<InviteMetadata[]>(
bot.rest,
"get",
bot.constants.endpoints.CHANNEL_INVITES(channelId),
);
return new Collection(
result.map((invite) => [
invite.code,
{
uses: invite.uses,
maxUses: invite.max_uses,
maxAge: invite.max_age,
temporary: invite.temporary,
createdAt: Date.parse(invite.created_at),
},
]),
);
}