I’m working with a PaginatedMessage in my command, where I display entities and use a dropdown (select menu) for users to choose an entity from the current page to view its details. However, if there are fewer than 10 entities, the dropdown doesn’t respond when selecting an entity, as if the command isn’t recognized as a PaginatedMessage. I suspect this may be because only one page is created, so the actions aren’t registered. I saw the setPageActions() method in the docs, could it help here?
I've included screenshots: one with fewer than 10 entities (not considered as a Paginated message) and one with more (Paginated message).
Thank you for your help !
listEntities method if needed :
protected async listEntities(interaction: CommandInteraction<CacheType>) { try { await interaction.deferReply({ ephemeral: true }); const ModelInstance = await this.Model; const entities = await ModelInstance.getAll(); if (entities.length === 0) { await interaction.reply({ content: `Aucune ${this.entityName} n'est enregistrée.`, ephemeral: true }); return; } const itemsPerPage = 10; const uniqueId = Date.now(); // Unique ID variable const paginatedMessage = new PaginatedMessage(); paginatedMessage.stopPaginatedMessageCustomIds = [`select_entity_${uniqueId}`]; for (let i = 0; i < entities.length; i += itemsPerPage) { const paginatedItems = entities.slice(i, i + itemsPerPage); const description = paginatedItems .map((entity, index) => `${i + index + 1}. ${entity.name || entity.label}`) .join('\n'); paginatedMessage.addPage({ embeds: [ new EmbedBuilder() .setTitle(`Liste des ${this.entityName}s (Page ${(i / itemsPerPage) + 1})`) .setColor('#0099ff') .setDescription(description) ], actions: [{ customId: `select_entity_${uniqueId}`, type: ComponentType.StringSelect, run: async (context: PaginatedMessageActionContext) => { const selectedEntityId = context.interaction.values[0]; await context.interaction.deferUpdate(); await this.showEntityDetails(context.interaction as StringSelectMenuInteraction, selectedEntityId); }, options: paginatedItems.map(entity => ({ label: entity.name || entity.label, value: entity.id })) }] }); } await paginatedMessage.run(interaction); } catch (error) { console.error(`Erreur lors de la récupération des ${this.entityName}s:`, error); await interaction.reply({ content: `Impossible de lister les ${this.entityName}s.`, ephemeral: true }); } }
protected async listEntities(interaction: CommandInteraction<CacheType>) { try { await interaction.deferReply({ ephemeral: true }); const ModelInstance = await this.Model; const entities = await ModelInstance.getAll(); if (entities.length === 0) { await interaction.reply({ content: `Aucune ${this.entityName} n'est enregistrée.`, ephemeral: true }); return; } const itemsPerPage = 10; const uniqueId = Date.now(); // Unique ID variable const paginatedMessage = new PaginatedMessage(); paginatedMessage.stopPaginatedMessageCustomIds = [`select_entity_${uniqueId}`]; for (let i = 0; i < entities.length; i += itemsPerPage) { const paginatedItems = entities.slice(i, i + itemsPerPage); const description = paginatedItems .map((entity, index) => `${i + index + 1}. ${entity.name || entity.label}`) .join('\n'); paginatedMessage.addPage({ embeds: [ new EmbedBuilder() .setTitle(`Liste des ${this.entityName}s (Page ${(i / itemsPerPage) + 1})`) .setColor('#0099ff') .setDescription(description) ], actions: [{ customId: `select_entity_${uniqueId}`, type: ComponentType.StringSelect, run: async (context: PaginatedMessageActionContext) => { const selectedEntityId = context.interaction.values[0]; await context.interaction.deferUpdate(); await this.showEntityDetails(context.interaction as StringSelectMenuInteraction, selectedEntityId); }, options: paginatedItems.map(entity => ({ label: entity.name || entity.label, value: entity.id })) }] }); } await paginatedMessage.run(interaction); } catch (error) { console.error(`Erreur lors de la récupération des ${this.entityName}s:`, error); await interaction.reply({ content: `Impossible de lister les ${this.entityName}s.`, ephemeral: true }); } }
Similar Threads
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
S-IaF
Sapphire - Imagine a Framework
Sapphire is a next-gen object-oriented Discord.js bot framework.