mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-08 03:27:20 +00:00
feat: add embed support to welcome messages
This commit is contained in:
parent
3ef89246ba
commit
25771f2527
3 changed files with 83 additions and 25 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue