diff --git a/src/buttonEvents/Inventory.ts b/src/buttonEvents/Inventory.ts index 84d8e14..b501fdb 100644 --- a/src/buttonEvents/Inventory.ts +++ b/src/buttonEvents/Inventory.ts @@ -26,6 +26,11 @@ export default class Inventory extends ButtonEvent { const embed = await InventoryHelper.GenerateInventoryPage(member.user.username, member.user.id, Number(page)); + if (!embed) { + await interaction.followUp("No page for user found."); + return; + } + await interaction.followUp({ files: [ embed.image ], embeds: [ embed.embed ], @@ -34,7 +39,7 @@ export default class Inventory extends ButtonEvent { } catch (e) { AppLogger.LogError("Button/Inventory", `Error generating inventory page for ${member.user.username} with id ${member.user.id}: ${e}`); - await interaction.reply("No page for user found."); + await interaction.followUp("An error has occurred running this command."); } } } diff --git a/src/commands/inventory.ts b/src/commands/inventory.ts index 0b48e2d..8d2ef2c 100644 --- a/src/commands/inventory.ts +++ b/src/commands/inventory.ts @@ -39,6 +39,11 @@ export default class Inventory extends Command { const embed = await InventoryHelper.GenerateInventoryPage(user.username, user.id, pageNumber); + if (!embed) { + await interaction.followUp("No page for user found."); + return; + } + await interaction.followUp({ files: [ embed.image ], embeds: [ embed.embed ], @@ -47,7 +52,7 @@ export default class Inventory extends Command { } catch (e) { AppLogger.LogError("Commands/Inventory", e as string); - await interaction.followUp("No page for user found."); + await interaction.followUp("An error has occurred running this command."); } } } diff --git a/src/helpers/InventoryHelper.ts b/src/helpers/InventoryHelper.ts index 99724cd..0218ef8 100644 --- a/src/helpers/InventoryHelper.ts +++ b/src/helpers/InventoryHelper.ts @@ -31,13 +31,15 @@ interface ReturnedInventoryPage { export default class InventoryHelper { - public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise { + public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise { AppLogger.LogSilly("Helpers/InventoryHelper", `Parameters: username=${username}, userid=${userid}, page=${page}`); const cardsPerPage = 9; const inventory = await Inventory.FetchAllByUserId(userid); + if (!inventory || inventory.length == 0) return undefined; + const clientCards = cloneDeep(CoreClient.Cards); const allSeriesClaimed = clientCards @@ -88,8 +90,7 @@ export default class InventoryHelper { const currentPage = pages[page]; if (!currentPage) { - AppLogger.LogError("Helpers/InventoryHelper", "Unable to find page"); - return Promise.reject("Unable to find page"); + return undefined; } const embed = new EmbedBuilder()