registration stepper/wizard

I want to make a registration stepper/wizard how do i create this using Discord.js i want to have a init reply where a user need to accept the rules after he has clicked the yes button i want to follow up with a modal
try {
let acceptedRules = false;
const firstButton = new ButtonBuilder()
.setLabel("Yes")
.setStyle(ButtonStyle.Success)
.setCustomId("yes-button")
const secondButton = new ButtonBuilder()
.setLabel("No")
.setStyle(ButtonStyle.Danger)
.setCustomId("no-button")
const buttonRow = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(firstButton, secondButton)
const reply = await interaction.reply({
content: "Have you read the rules?",
components: [buttonRow],
ephemeral: true
});
const collector = reply.createMessageComponentCollector({componentType: ComponentType.Button, time: 5000})
collector.on("collect", async buttonInteraction => {
if (buttonInteraction.customId === "yes-button") {
await buttonInteraction.update({content: "You have accepted the rules."})
acceptedRules = true
collector.stop()
}
if (buttonInteraction.customId === "no-button") {
collector.stop()
}

})
collector.on("end", async () => {
if (!acceptedRules) {
await interaction.followUp({
content: "You must accept the rules to register!",
ephemeral: true
})
}
await interaction.deleteReply("@original")
})
try {
let acceptedRules = false;
const firstButton = new ButtonBuilder()
.setLabel("Yes")
.setStyle(ButtonStyle.Success)
.setCustomId("yes-button")
const secondButton = new ButtonBuilder()
.setLabel("No")
.setStyle(ButtonStyle.Danger)
.setCustomId("no-button")
const buttonRow = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(firstButton, secondButton)
const reply = await interaction.reply({
content: "Have you read the rules?",
components: [buttonRow],
ephemeral: true
});
const collector = reply.createMessageComponentCollector({componentType: ComponentType.Button, time: 5000})
collector.on("collect", async buttonInteraction => {
if (buttonInteraction.customId === "yes-button") {
await buttonInteraction.update({content: "You have accepted the rules."})
acceptedRules = true
collector.stop()
}
if (buttonInteraction.customId === "no-button") {
collector.stop()
}

})
collector.on("end", async () => {
if (!acceptedRules) {
await interaction.followUp({
content: "You must accept the rules to register!",
ephemeral: true
})
}
await interaction.deleteReply("@original")
})
5 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Skylife
Skylife2mo ago
is it possible to do it after i deleted the first reply? because after the modal i need a select menu 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 then i do all code after the button inside the collector event?
d.js docs
d.js docs2mo ago
:method: Message#awaitMessageComponent @14.15.2 Collects a single component interaction that passes the filter. The Promise will reject if the time expires.
// Collect a message component interaction
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
message.awaitMessageComponent({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was clicked!`))
.catch(console.error);
// Collect a message component interaction
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
message.awaitMessageComponent({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was clicked!`))
.catch(console.error);
:method: ButtonInteraction#awaitModalSubmit @14.15.2 Collects a single modal submit interaction that passes the filter. The Promise will reject if the time expires.
// Collect a modal submit interaction
const filter = (interaction) => interaction.customId === 'modal';
interaction.awaitModalSubmit({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was submitted!`))
.catch(console.error);
// Collect a modal submit interaction
const filter = (interaction) => interaction.customId === 'modal';
interaction.awaitModalSubmit({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was submitted!`))
.catch(console.error);
Skylife
Skylife2mo ago
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' } why is the interaction already sent or deferred? but its still the same issue ah okay but qjuh is it possible to delete the first response as well after the user pressed the yes button?
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)
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 ...
Want results from more Discord servers?
Add your server
More Posts
If I receive two messages on the same channel, I want to be able to retrieve both of them separatelyI pressed the wrong button. I am reposting. Sorry for the long title. I would like to do exactly whaIf I receive two messages on the same channel, I want to be able to retrieve both of them separatelySorry for the long title. I have been doing JS for a year or two and I am still a beginner. I would An invalid token was provided.I reseted my token and i did put in my config.json ```json { "token_secret":"" } ``` ```js consChange Role icon (Emoji)I want to change the icon for a specific roll with an emoji. I'm trying to do that, but I'm getting How can i add no prefix system into my bot??I have to create a full no prefix system along with no prefix add remove list command how can i do tBot responding with 2 or 3 messages instead of 1 after being not used for a whilehi, anyone can help me? i have an guildMemberAdd event to welcome my new members on server which senProperty 'getMessage' does not existHello, I've just updated to the latest version of discord.js and I can't seem to access the getMessaRecurring EventsI'm putting my guild events onto a website calendar, but I'm having a hard time dealing with recurriError when trying to upload global slash commandsI have no idea why I am getting this error. When I register slash commands locally everything works MongooseError: Model.findOne() no longer accepts a callbackHello I coded an auditlog system and now I have a problem and I can't get it solved can someone help