Skylife
Skylife
DIAdiscord.js - Imagine an app
Created by Skylife on 6/16/2024 in #djs-questions
pagination with button handler
Ah okay understood no it’s not like that every page has different data
9 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 6/16/2024 in #djs-questions
pagination with button handler
What do you mean data does not change it is possible that the data is changing
9 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 6/16/2024 in #djs-questions
pagination with button handler
the data for the embed i get through my backend(API) and my idea is now i just create one embed in the beginning then when the user press the next button i fetch the second page from my backend and edit the current embed with the new data
9 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 6/16/2024 in #djs-questions
pagination with button handler
true thx so maybe i implement paginatioon oin my api so i always fetch the current page what do you think?
9 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 6/16/2024 in #djs-questions
pagination with button handler
because when the bot restarts etc. the interaction fails
9 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 6/16/2024 in #djs-questions
pagination with button handler
collector.on("collect", async (interaction: CollectedMessageInteraction) => {
await interaction.deferUpdate();
if (interaction.customId === "pagefirst") {
pageCount.setLabel(`${index + 1}/${embeds.length}`)
}
if (interaction.customId === "pageprev") {
if (index > 0) index--;
pageCount.setLabel(`${index + 1}/${embeds.length}`)
} else if (interaction.customId === "pagenext") {
if (index < embeds.length - 1) {
index++;
pageCount.setLabel(`${index + 1}/${embeds.length}`)
}
} else if (interaction.customId === "pagelast") {
index = embeds.length - 1;
pageCount.setLabel(`${index + 1}/${embeds.length}`)
}
if (index === 0) {
first.setDisabled(true);
prev.setDisabled(true);
} else {
first.setDisabled(false);
prev.setDisabled(false);
}
if (index === embeds.length - 1) {
next.setDisabled(true);
last.setDisabled(true);
} else {
next.setDisabled(false);
last.setDisabled(false);
}
await msg.edit({embeds: [embeds[index]], components: [buttons]}).catch(err => {
});
});
return msg;
} catch (error) {
console.error(error)
}
}
collector.on("collect", async (interaction: CollectedMessageInteraction) => {
await interaction.deferUpdate();
if (interaction.customId === "pagefirst") {
pageCount.setLabel(`${index + 1}/${embeds.length}`)
}
if (interaction.customId === "pageprev") {
if (index > 0) index--;
pageCount.setLabel(`${index + 1}/${embeds.length}`)
} else if (interaction.customId === "pagenext") {
if (index < embeds.length - 1) {
index++;
pageCount.setLabel(`${index + 1}/${embeds.length}`)
}
} else if (interaction.customId === "pagelast") {
index = embeds.length - 1;
pageCount.setLabel(`${index + 1}/${embeds.length}`)
}
if (index === 0) {
first.setDisabled(true);
prev.setDisabled(true);
} else {
first.setDisabled(false);
prev.setDisabled(false);
}
if (index === embeds.length - 1) {
next.setDisabled(true);
last.setDisabled(true);
} else {
next.setDisabled(false);
last.setDisabled(false);
}
await msg.edit({embeds: [embeds[index]], components: [buttons]}).catch(err => {
});
});
return msg;
} catch (error) {
console.error(error)
}
}
9 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 6/16/2024 in #djs-questions
pagination with button handler
so what I want is to have the logic collector.on in my handleSpotNext/BackButton
export const pagination = async (interaction, embeds: EmbedBuilder[], time = 30 * 1000) => {
try {
if (!interaction || !embeds) throw new Error("[PAGINATION] Invalid parameters")
// await interaction.deferReply();
if (embeds.length === 1) return await interaction.channel!.send({embeds, fetchReply: true});
let index = 0;
const first = new ButtonBuilder()
.setCustomId("pagefirst")
.setEmoji("⏪")
.setStyle(ButtonStyle.Primary)
.setDisabled(true);

const prev = new ButtonBuilder()
.setCustomId("pageprev")
.setEmoji("◀")
.setStyle(ButtonStyle.Primary)
.setDisabled(true);

const pageCount = new ButtonBuilder()
.setCustomId("pagecount")
.setLabel(`${index + 1}/${embeds.length}`)
.setStyle(ButtonStyle.Primary)
.setDisabled(true);

const next = new ButtonBuilder()
.setCustomId("pagenext")
.setEmoji("▶")
.setStyle(ButtonStyle.Primary)

const last = new ButtonBuilder()
.setCustomId("pagelast")
.setEmoji("⏩")
.setStyle(ButtonStyle.Primary)

const buttons = new ActionRowBuilder().addComponents([first, prev, pageCount, next, last]);
const msg = await interaction.channel!.send({embeds: [embeds[index]], components: [buttons], fetchReply: true});
const collector = msg.createMessageComponentCollector({
componentType: ComponentType.Button,
});
export const pagination = async (interaction, embeds: EmbedBuilder[], time = 30 * 1000) => {
try {
if (!interaction || !embeds) throw new Error("[PAGINATION] Invalid parameters")
// await interaction.deferReply();
if (embeds.length === 1) return await interaction.channel!.send({embeds, fetchReply: true});
let index = 0;
const first = new ButtonBuilder()
.setCustomId("pagefirst")
.setEmoji("⏪")
.setStyle(ButtonStyle.Primary)
.setDisabled(true);

const prev = new ButtonBuilder()
.setCustomId("pageprev")
.setEmoji("◀")
.setStyle(ButtonStyle.Primary)
.setDisabled(true);

const pageCount = new ButtonBuilder()
.setCustomId("pagecount")
.setLabel(`${index + 1}/${embeds.length}`)
.setStyle(ButtonStyle.Primary)
.setDisabled(true);

const next = new ButtonBuilder()
.setCustomId("pagenext")
.setEmoji("▶")
.setStyle(ButtonStyle.Primary)

const last = new ButtonBuilder()
.setCustomId("pagelast")
.setEmoji("⏩")
.setStyle(ButtonStyle.Primary)

const buttons = new ActionRowBuilder().addComponents([first, prev, pageCount, next, last]);
const msg = await interaction.channel!.send({embeds: [embeds[index]], components: [buttons], fetchReply: true});
const collector = msg.createMessageComponentCollector({
componentType: ComponentType.Button,
});
9 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
oh i was missing a costum id the error is a bit confusing do you know why i dont get a error like you are missing ...
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle (C:\gitrepos\tii-api\node_modules\@sapphire\shapeshift\src\validators\StringValidator.ts:23:73)
at _StringValidator.parse (C:\gitrepos\tii-api\node_modules\@sapphire\shapeshift\src\validators\BaseValidator.ts:103:2)
at validateRequiredParameters (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\textInput\Assertions.ts:24:20)
at TextInputBuilder.toJSON (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\textInput\TextInput.ts:135:3)
at C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\ActionRow.ts:132:61
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\ActionRow.ts:132:32)
at C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\interactions\modals\Modal.ts:98:61
at Array.map (<anonymous>)
at ModalBuilder.toJSON (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\interactions\modals\Modal.ts:98:32)
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle (C:\gitrepos\tii-api\node_modules\@sapphire\shapeshift\src\validators\StringValidator.ts:23:73)
at _StringValidator.parse (C:\gitrepos\tii-api\node_modules\@sapphire\shapeshift\src\validators\BaseValidator.ts:103:2)
at validateRequiredParameters (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\textInput\Assertions.ts:24:20)
at TextInputBuilder.toJSON (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\textInput\TextInput.ts:135:3)
at C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\ActionRow.ts:132:61
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\components\ActionRow.ts:132:32)
at C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\interactions\modals\Modal.ts:98:61
at Array.map (<anonymous>)
at ModalBuilder.toJSON (C:\gitrepos\tii-api\node_modules\@discordjs\builders\src\interactions\modals\Modal.ts:98:32)
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
but qjuh is it possible to delete the first response as well after the user pressed the yes button?
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
ah okay
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
but its still the same issue
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
why is the interaction already sent or deferred?
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
try {
const buttonRow = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(firstButton, secondButton)
const reply = await interaction.reply({
content: "Have you read the rules?",
components: [buttonRow],
ephemeral: true
});

const buttonInteraction = await reply.awaitMessageComponent({componentType: ComponentType.Button, time: 5000})
if (buttonInteraction.customId === "no-button") {
await interaction.followUp({
content: "You must accept the rules to register!",
ephemeral: true
})

}
if (buttonInteraction.customId === "yes-button"){
// await interaction.deleteReply("@original")
await buttonInteraction.update({content: "You accepted the rules!"})
const modal = new ModalBuilder().setTitle("Modal").setCustomId("myModal");
const characterNameInput = new TextInputBuilder().setLabel("Character Name").setPlaceholder("Enter your character name").setStyle(TextInputStyle.Short).setRequired(true).setMaxLength(100);
const characterActionRow = new ActionRowBuilder<TextInputBuilder>().addComponents(characterNameInput);
modal.addComponents(characterActionRow);
await interaction.showModal(modal)
}
try {
const buttonRow = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(firstButton, secondButton)
const reply = await interaction.reply({
content: "Have you read the rules?",
components: [buttonRow],
ephemeral: true
});

const buttonInteraction = await reply.awaitMessageComponent({componentType: ComponentType.Button, time: 5000})
if (buttonInteraction.customId === "no-button") {
await interaction.followUp({
content: "You must accept the rules to register!",
ephemeral: true
})

}
if (buttonInteraction.customId === "yes-button"){
// await interaction.deleteReply("@original")
await buttonInteraction.update({content: "You accepted the rules!"})
const modal = new ModalBuilder().setTitle("Modal").setCustomId("myModal");
const characterNameInput = new TextInputBuilder().setLabel("Character Name").setPlaceholder("Enter your character name").setStyle(TextInputStyle.Short).setRequired(true).setMaxLength(100);
const characterActionRow = new ActionRowBuilder<TextInputBuilder>().addComponents(characterNameInput);
modal.addComponents(characterActionRow);
await interaction.showModal(modal)
}
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. at ChatInputCommandInteraction.showModal (C:\gitrepos\tii-api\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:255:46) at Object.execute (C:\gitrepos\tii-api\src\bot\slashCommands\register.ts:48:35) at processTicksAndRejections (node:internal/process/task_queues:95:5) { code: 'InteractionAlreadyReplied' }
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
then i do all code after the button inside the collector event?
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
could you explain me the workflow a bit more in detail? i have at first a button where u need to select yes then i want to show a modal after the modal a select menu
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
because after the modal i need a select menu
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 5/26/2024 in #djs-questions
registration stepper/wizard
is it possible to do it after i deleted the first reply?
16 replies
DIAdiscord.js - Imagine an app
Created by Skylife on 2/22/2024 in #djs-questions
getting guild object
just when an event happens i want to check if my api is online - like a middleware so if not i can return early and notify the server owner once.
6 replies
DIAdiscord.js - Imagine an app
Created by Hunter シ on 12/23/2023 in #djs-questions
Anyone Know how to catch this error so the bot doesn't go offline?
and handle your error accordingly
4 replies