mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-17 11:48:17 +00:00
29 lines
884 B
TypeScript
29 lines
884 B
TypeScript
import { botId } from "../../bot.ts";
|
|
import { cacheHandlers } from "../../cache.ts";
|
|
import { rest } from "../../rest/rest.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|
import { delay } from "../../util/utils.ts";
|
|
|
|
/** Delete a message with the channel id and message id only. */
|
|
export async function deleteMessage(
|
|
channelId: string,
|
|
messageId: string,
|
|
reason?: string,
|
|
delayMilliseconds = 0,
|
|
) {
|
|
const message = await cacheHandlers.get("messages", messageId);
|
|
|
|
if (message && message.author.id !== botId) {
|
|
await requireBotChannelPermissions(message.channelId, ["MANAGE_MESSAGES"]);
|
|
}
|
|
|
|
if (delayMilliseconds) await delay(delayMilliseconds);
|
|
|
|
return await rest.runMethod<undefined>(
|
|
"delete",
|
|
endpoints.CHANNEL_MESSAGE(channelId, messageId),
|
|
{ reason },
|
|
);
|
|
}
|