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

18 lines
668 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.endpoints.CHANNEL_BULK_DELETE(channelId), {
messages: ids.splice(0, 100).map((id) => id.toString()),
reason,
});
}