mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { rest } from "../../rest/rest.ts";
|
|
import { structures } from "../../structures/mod.ts";
|
|
import { Errors } from "../../types/misc/errors.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
|
|
export async function editWebhookMessage(
|
|
webhookId: string,
|
|
webhookToken: string,
|
|
messageId: string,
|
|
options: EditWebhookMessageOptions,
|
|
) {
|
|
if (options.content && options.content.length > 2000) {
|
|
throw Error(Errors.MESSAGE_MAX_LENGTH);
|
|
}
|
|
|
|
if (options.embeds && options.embeds.length > 10) {
|
|
options.embeds.splice(10);
|
|
}
|
|
|
|
if (options.allowed_mentions) {
|
|
if (options.allowed_mentions.users?.length) {
|
|
if (options.allowed_mentions.parse.includes("users")) {
|
|
options.allowed_mentions.parse = options.allowed_mentions.parse.filter(
|
|
(p) => p !== "users",
|
|
);
|
|
}
|
|
|
|
if (options.allowed_mentions.users.length > 100) {
|
|
options.allowed_mentions.users = options.allowed_mentions.users.slice(
|
|
0,
|
|
100,
|
|
);
|
|
}
|
|
}
|
|
|
|
if (options.allowed_mentions.roles?.length) {
|
|
if (options.allowed_mentions.parse.includes("roles")) {
|
|
options.allowed_mentions.parse = options.allowed_mentions.parse.filter(
|
|
(p) => p !== "roles",
|
|
);
|
|
}
|
|
|
|
if (options.allowed_mentions.roles.length > 100) {
|
|
options.allowed_mentions.roles = options.allowed_mentions.roles.slice(
|
|
0,
|
|
100,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
const result = await rest.runMethod(
|
|
"patch",
|
|
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
|
|
{ ...options, allowed_mentions: options.allowed_mentions },
|
|
) as MessageCreateOptions;
|
|
|
|
const message = await structures.createMessageStruct(result);
|
|
return message;
|
|
}
|