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)=>{
const errorData = await e.response.json();
if(MESSAGE_BLOCK_REASONS[errorData.code]){
// Delete the public response
await context.deleteResponse();
message.flags = MessageFlags.EPHEMERAL
try{
// Create a notice
if(message.content){
if(message.embeds && message.embeds.length <= 4){
message.embeds.unshift({
description: `${icon("flask_incognito")} This response has been made incognito due to ${MESSAGE_BLOCK_REASONS[errorData.code].message}.`,
color: COLORS.incognito
})
const errorData = await e.response.json();
if(MESSAGE_BLOCK_REASONS[errorData.code]){
// Delete the public response
await context.deleteResponse();
message.flags = MessageFlags.EPHEMERAL
// Create a notice
if(message.content){
if(message.embeds && message.embeds.length <= 4){
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"
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")}`
}
let replacementMessage = await context.createMessage(message);
if(!context._meta) context._meta = {}
context._meta.replacementMessageId = replacementMessage.id;
return replacementMessage;
let replacementMessage = await context.createMessage(message);
if(!context._meta) context._meta = {}
context._meta.replacementMessageId = replacementMessage.id;
return replacementMessage;
}
}catch(e){
console.log(e)
}
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);
})