3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-08 03:27:20 +00:00
This commit is contained in:
seeyebe 2025-06-25 20:33:44 +01:00 committed by GitHub
commit c36a1e5688
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 83 additions and 25 deletions

View file

@ -1,4 +1,4 @@
import { MessagePayload, User } from "discord.js";
import { MessagePayload, User, MessageCreateOptions } from "discord.js";
import { logger } from "../logger.js";
import { HOURS, createChunkedMessage, isDiscordAPIError } from "../utils.js";
import Timeout = NodeJS.Timeout;
@ -16,7 +16,11 @@ export class DMError extends Error {}
const error20026 = "The bot cannot currently send DMs";
export async function sendDM(user: User, content: string | MessagePayload, source: string) {
export async function sendDM(
user: User,
content: string | MessagePayload | MessageCreateOptions,
source: string
) {
if (dmsDisabled) {
throw new DMError(error20026);
}
@ -26,8 +30,22 @@ export async function sendDM(user: User, content: string | MessagePayload, sourc
try {
if (typeof content === "string") {
await createChunkedMessage(user, content);
} else {
} else if (content instanceof MessagePayload) {
await user.send(content);
} else {
if (content.embeds && content.embeds.length > 0) {
await user.send({
...content,
allowedMentions: {
parse: ["users"],
...content.allowedMentions
}
});
} else if (content.content) {
await createChunkedMessage(user, content.content, content.allowedMentions);
} else {
await user.send(content);
}
}
} catch (e) {
if (isDiscordAPIError(e) && e.code === 20026) {
@ -36,7 +54,6 @@ export async function sendDM(user: User, content: string | MessagePayload, sourc
disableDMs(1 * HOURS);
throw new DMError(error20026);
}
throw e;
}
}
}