Add console log on drop command error

This commit is contained in:
Ethan Lane 2023-12-13 17:32:51 +00:00
parent 2ddb170b48
commit 7a72be4e64
2 changed files with 28 additions and 43 deletions

View file

@ -27,15 +27,11 @@ export default class Reroll extends ButtonEvent {
return; return;
} }
try {
let image: Buffer; let image: Buffer;
const imageFileName = randomCard.card.path.split("/").pop()!; const imageFileName = randomCard.card.path.split("/").pop()!;
try {
image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path)); image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
} catch {
await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`);
return;
}
await interaction.deferReply(); await interaction.deferReply();
@ -50,22 +46,18 @@ export default class Reroll extends ButtonEvent {
const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id);
try {
await interaction.editReply({ await interaction.editReply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: [ attachment ],
components: [ row ], components: [ row ],
}); });
CoreClient.ClaimId = claimId;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
if (e instanceof DiscordAPIError) { await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`);
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
} else {
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`);
} }
} }
CoreClient.ClaimId = claimId;
}
} }

View file

@ -35,15 +35,11 @@ export default class Drop extends Command {
return; return;
} }
try {
let image: Buffer; let image: Buffer;
const imageFileName = randomCard.card.path.split("/").pop()!; const imageFileName = randomCard.card.path.split("/").pop()!;
try {
image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path)); image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
} catch {
await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`);
return;
}
await interaction.deferReply(); await interaction.deferReply();
@ -58,22 +54,19 @@ export default class Drop extends Command {
const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id);
try {
await interaction.editReply({ await interaction.editReply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: [ attachment ],
components: [ row ], components: [ row ],
}); });
CoreClient.ClaimId = claimId;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
if (e instanceof DiscordAPIError) { await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`);
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
} else {
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`);
}
} }
CoreClient.ClaimId = claimId;
} }
} }