mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
fix(core): resolve unhandled rejections on 403s and undefined channel guildId
This commit is contained in:
1 parent
a467611e37
commit
5714f7b2c8
5 files changed
+91
-24
No files matched your search
@@ -395,7 +395,15 @@ export class MessageHandler {
|
||||
} else {
|
||||
opts = { ...message };
|
||||
}
|
||||
return new Message(await replyingTo.reply(opts, { ping: false }), this);
|
||||
try {
|
||||
return new Message(await replyingTo.reply(opts, { ping: false }), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot reply in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,7 +417,15 @@ export class MessageHandler {
|
||||
if (!(await this.assertPermissions(["SendMessages", "EmbedLinks"], replyingTo))) return null;
|
||||
|
||||
if (typeof message === "object" && Array.isArray(message.embeds)) {
|
||||
return new Message(await replyingTo.reply(message, { ping: false }), this);
|
||||
try {
|
||||
return new Message(await replyingTo.reply(message, { ping: false }), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
options = {
|
||||
@@ -423,7 +439,15 @@ export class MessageHandler {
|
||||
const { embedText, ...rest } = message;
|
||||
payload = { ...payload, ...rest };
|
||||
}
|
||||
return new Message(await replyingTo.reply(payload, { ping: false }), this);
|
||||
try {
|
||||
return new Message(await replyingTo.reply(payload, { ping: false }), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,7 +467,15 @@ export class MessageHandler {
|
||||
} else {
|
||||
opts = message;
|
||||
}
|
||||
return new Message(await channel.send(opts), this);
|
||||
try {
|
||||
return new Message(await channel.send(opts), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot sendMessage in channel ${channel.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,7 +490,15 @@ export class MessageHandler {
|
||||
return this.sendMessage(channel, typeof content === "string" ? content : content?.embedText ?? "");
|
||||
}
|
||||
if (typeof content === "object" && Array.isArray(content.embeds)) {
|
||||
return new Message(await channel.send(content), this);
|
||||
try {
|
||||
return new Message(await channel.send(content), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot sendEmbed in channel ${channel.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const text = (typeof content === "object") ? content.embedText : content;
|
||||
const payload = this.#createEmbed(text, embedOptions);
|
||||
@@ -466,7 +506,15 @@ export class MessageHandler {
|
||||
const { embedText, ...rest } = content;
|
||||
Object.assign(payload, rest);
|
||||
}
|
||||
return new Message(await channel.send(payload), this);
|
||||
try {
|
||||
return new Message(await channel.send(payload), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot sendEmbed in channel ${channel.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -503,6 +551,11 @@ export class MessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] editEmbed: missing permissions or communication disabled: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (RETRYABLE.has(err.statusCode) && attempt < MAX_ATTEMPTS) {
|
||||
logger.warn(`[MessageHandler] editEmbed: ${err.statusCode} on attempt ${attempt}/${MAX_ATTEMPTS}, retrying in ${RETRY_DELAY_MS}ms…`);
|
||||
await new Promise(r => setTimeout(r, RETRY_DELAY_MS));
|
||||
|
||||
Reference in new issue
Block a user