Skip to content

Commit

Permalink
fix(worker): Catch error when sending msg log
Browse files Browse the repository at this point in the history
  • Loading branch information
tzushimelon committed Feb 7, 2024
1 parent 6c9eea0 commit b0f8cfb
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/sushii-worker/src/events/msglog/MsgLogHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,28 @@ export async function msgLogHandler(
return;
}

// Split embeds into chunks of 10
const chunkSize = 10;
for (let i = 0; i < embeds.val.length; i += chunkSize) {
const chunk = embeds.val.slice(i, i + chunkSize).map((e) => e.toJSON());

// eslint-disable-next-line no-await-in-loop
await channel.send({
embeds: chunk,
});
// Only attempt if first chunk fails, likely due to permission error so don't try
// all chunks
try {
// Split embeds into chunks of 10
const chunkSize = 10;
for (let i = 0; i < embeds.val.length; i += chunkSize) {
const chunk = embeds.val.slice(i, i + chunkSize).map((e) => e.toJSON());

// eslint-disable-next-line no-await-in-loop
await channel.send({
embeds: chunk,
});
}
} catch (err) {
logger.warn(
{
guildId: payload.guild_id,
channelId: guildConfig.log_msg,
error: err,
},
"Failed to send message log",
);
}
}

Expand Down

0 comments on commit b0f8cfb

Please sign in to comment.