mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { botId } from "../../bot.ts";
|
|
import { rest } from "../../rest/rest.ts";
|
|
import { Message, structures } from "../../structures/mod.ts";
|
|
import { Errors } from "../../types/misc/errors.ts";
|
|
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|
|
|
/** Edit the message. */
|
|
export async function editMessage(
|
|
message: Message,
|
|
content: string | MessageContent,
|
|
) {
|
|
if (message.author.id !== botId) {
|
|
throw "You can only edit a message that was sent by the bot.";
|
|
}
|
|
|
|
if (typeof content === "string") content = { content };
|
|
|
|
const requiredPerms: PermissionStrings[] = ["SEND_MESSAGES"];
|
|
|
|
if (content.tts) requiredPerms.push("SEND_TTS_MESSAGES");
|
|
|
|
await requireBotChannelPermissions(message.channelId, requiredPerms);
|
|
|
|
if (content.content && content.content.length > 2000) {
|
|
throw new Error(Errors.MESSAGE_MAX_LENGTH);
|
|
}
|
|
|
|
const result = await rest.runMethod(
|
|
"patch",
|
|
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
|
|
content,
|
|
);
|
|
|
|
return structures.createMessageStruct(result as MessageCreateOptions);
|
|
}
|