Files
discordeno/helpers/messages/deleteMessages.ts
ITOH 03996c5f58 refactor: revert "feat: base plugin lib idea (#2308)" (#2336)
* Revert "feat: base plugin lib idea (#2308)"

This reverts commit ffe7cdbc6f.

* fmt
2022-07-02 14:24:43 +01:00

18 lines
665 B
TypeScript

import type { Bot } from "../../bot.ts";
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
export async function deleteMessages(bot: Bot, channelId: bigint, ids: bigint[], reason?: string) {
if (ids.length < 2) {
throw new Error(bot.constants.Errors.DELETE_MESSAGES_MIN);
}
if (ids.length > 100) {
console.warn(`This endpoint only accepts a maximum of 100 messages. Deleting the first 100 message ids provided.`);
}
await bot.rest.runMethod<undefined>(bot.rest, "POST", bot.constants.routes.CHANNEL_BULK_DELETE(channelId), {
messages: ids.splice(0, 100).map((id) => id.toString()),
reason,
});
}