mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
refactor(helpers): rename & replace deleteMessageByID() with deleteMessage() (#668)
* refactor(helpers): rename & replace deleteMessageByID() with deleteMessage() * changes * fix * fix * Update src/types/errors.ts
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
import { botID } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { RequestManager } from "../../rest/request_manager.ts";
|
||||
import { Message } from "../../structures/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
import { delay } from "../../util/utils.ts";
|
||||
|
||||
/** Delete a message */
|
||||
/** Delete a message with the channel id and message id only. */
|
||||
export async function deleteMessage(
|
||||
message: Message,
|
||||
channelID: string,
|
||||
messageID: string,
|
||||
reason?: string,
|
||||
delayMilliseconds = 0,
|
||||
) {
|
||||
if (message.author.id !== botID) {
|
||||
// This needs to check the channels permission not the guild permission
|
||||
const message = await cacheHandlers.get("messages", messageID);
|
||||
|
||||
if (message && message.author.id !== botID) {
|
||||
await requireBotChannelPermissions(message.channelID, ["MANAGE_MESSAGES"]);
|
||||
}
|
||||
|
||||
if (delayMilliseconds) await delay(delayMilliseconds);
|
||||
|
||||
const result = await RequestManager.delete(
|
||||
endpoints.CHANNEL_MESSAGE(message.channelID, message.id),
|
||||
endpoints.CHANNEL_MESSAGE(channelID, messageID),
|
||||
{ reason },
|
||||
);
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { RequestManager } from "../../rest/request_manager.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { delay } from "../../util/utils.ts";
|
||||
import { deleteMessage } from "./delete_message.ts";
|
||||
|
||||
/** Delete a message with the channel id and message id only. */
|
||||
export async function deleteMessageByID(
|
||||
channelID: string,
|
||||
messageID: string,
|
||||
reason?: string,
|
||||
delayMilliseconds = 0,
|
||||
) {
|
||||
const message = await cacheHandlers.get("messages", messageID);
|
||||
if (message) return deleteMessage(message, reason, delayMilliseconds);
|
||||
|
||||
if (delayMilliseconds) await delay(delayMilliseconds);
|
||||
|
||||
const result = await RequestManager.delete(
|
||||
endpoints.CHANNEL_MESSAGE(channelID, messageID),
|
||||
{ reason },
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user