catch potential crash issue

This commit is contained in:
bignutty 2025-02-09 20:31:47 +01:00
parent e23053650e
commit bbf34590c6

View file

@ -48,33 +48,37 @@ module.exports.editOrReply = function(context, message, disableReference = false
} }
return context.editOrRespond(message).catch(async (e)=>{ return context.editOrRespond(message).catch(async (e)=>{
const errorData = await e.response.json(); try{
if(MESSAGE_BLOCK_REASONS[errorData.code]){
// Delete the public response
await context.deleteResponse();
message.flags = MessageFlags.EPHEMERAL const errorData = await e.response.json();
if(MESSAGE_BLOCK_REASONS[errorData.code]){
// Delete the public response
await context.deleteResponse();
// Create a notice message.flags = MessageFlags.EPHEMERAL
if(message.content){
if(message.embeds && message.embeds.length <= 4){ // Create a notice
message.embeds.unshift({ if(message.content){
description: `${icon("flask_incognito")} This response has been made incognito due to ${MESSAGE_BLOCK_REASONS[errorData.code].message}.`, if(message.embeds && message.embeds.length <= 4){
color: COLORS.incognito message.embeds.unshift({
}) description: `${icon("flask_incognito")} This response has been made incognito due to ${MESSAGE_BLOCK_REASONS[errorData.code].message}.`,
color: COLORS.incognito
})
}
} else {
// Uses new subtext formatting to look more "native"
message.content = `-# ${icon("flask_mini")} This response has been made incognito due to ${MESSAGE_BLOCK_REASONS[errorData.code].message}${link("https://support.discord.com/hc/en-us/articles/" + MESSAGE_BLOCK_REASONS[errorData.code].support_article, "Learn More", "Support Article")}`
} }
} else {
// Uses new subtext formatting to look more "native" let replacementMessage = await context.createMessage(message);
message.content = `-# ${icon("flask_mini")} This response has been made incognito due to ${MESSAGE_BLOCK_REASONS[errorData.code].message}${link("https://support.discord.com/hc/en-us/articles/" + MESSAGE_BLOCK_REASONS[errorData.code].support_article, "Learn More", "Support Article")}`
if(!context._meta) context._meta = {}
context._meta.replacementMessageId = replacementMessage.id;
return replacementMessage;
} }
}catch(e){
let replacementMessage = await context.createMessage(message); console.log(e)
if(!context._meta) context._meta = {}
context._meta.replacementMessageId = replacementMessage.id;
return replacementMessage;
} }
basecamp(formatErrorMessage(3, "SHARD_MESSAGE_ERROR", `\`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``), message); basecamp(formatErrorMessage(3, "SHARD_MESSAGE_ERROR", `\`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``), message);
}) })