You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Press either the smash or pass button in Discord client
interaction.content should update to "Game over!" and there should be something logged in the console that says "stopped"
Collection.stop() works perfectly fine provided there is pagination input. But if someone presses smash or pass without paginating then it does not fire off.
Code sample
module.exports={data: newSlashCommandBuilder().setName('smash').setDescription('Would you smash this Gundam?'),asyncexecute(interaction){letcurrentPage=0;letgetSmashesSQL=`SELECT SMASHES FROM MOBILE_WEAPONS WHERE NAME = ?`;letgetPassesSQL=`SELECT PASSES FROM MOBILE_WEAPONS WHERE NAME = ?`;letsmashes;letpasses;constnum=randomNum(0,4);constname=gundams[num].title;constnameLower=name.toLowerCase();constimages=gundams[num].images;letembeds=[];for(imageinimages){letembed=newEmbedBuilder().setTitle(`Would you smash the ${name}?`).setImage(images[image])embeds.push(embed)}constsmash=newButtonBuilder().setCustomId(`${nameLower}-smash`).setLabel('Smash').setStyle(ButtonStyle.Success);constpass=newButtonBuilder().setCustomId(`${nameLower}-pass`).setLabel('Pass').setStyle(ButtonStyle.Danger);constback=newButtonBuilder().setCustomId("page-back").setLabel("Previous Page").setEmoji("◀️").setStyle(ButtonStyle.Primary).setDisabled(true);constforward=newButtonBuilder().setCustomId("page-forward").setLabel("Next Page").setEmoji("▶️").setStyle(ButtonStyle.Primary)letvoteActions;if(images.length>1){voteActions=newActionRowBuilder().addComponents(back,smash,pass,forward);}else{voteActions=newActionRowBuilder().addComponents(back.setDisabled(true),smash,pass,forward.setDisabled(true));}db.get(getSmashesSQL,[nameLower],(err,row)=>{if(err){returnconsole.error(err.message);}smashes=row.SMASHES;});db.get(getPassesSQL,[nameLower],(err,row)=>{if(err){returnconsole.error(err.message);}passes=row.PASSES;});awaitinteraction.reply({content: ":eyes:",embeds: [embeds[0]],components: [voteActions],ephemeral: true,fetchReply: true}).then(sentInteraction=>{constfilter=(i)=>['page-back','page-forward',`${nameLower}-smash`,`${nameLower}-pass`].includes(i.customId)&&i.user.id===interaction.user.id;constcollector=sentInteraction.createMessageComponentCollector({filter: filter,componentType: ComponentType.Button,time: 60_000,idle: 60_000,dispose: true,});collector.on('collect',async(i)=>{constresultsEmbed=newEmbedBuilder().setTitle(`Here's how other people voted on the ${name}!`).setImage(images[currentPage])if(i.customId==='page-back'&¤tPage===1){currentPage--;voteActions=newActionRowBuilder().addComponents(back.setDisabled(true),smash,pass,forward.setDisabled(false));awaiti.update({content: ":eyes:",embeds: [embeds[currentPage]],components: [voteActions],});}elseif(i.customId==='page-forward'&¤tPage===(embeds.length-2)){currentPage++;voteActions=newActionRowBuilder().addComponents(back.setDisabled(false),smash,pass,forward.setDisabled(true));awaiti.update({content: ":eyes:",embeds: [embeds[currentPage]],components: [voteActions],});}elseif(i.customId==='page-back'||i.customId==='page-forward'&¤tPage>=0&¤tPage<embeds.length-1){if(i.customId==='page-back'){currentPage--;}elseif(i.customId==='page-forward'){currentPage++;}voteActions=newActionRowBuilder().addComponents(back.setDisabled(false),smash,pass,forward.setDisabled(false));awaiti.update({content: ":eyes:",embeds: [embeds[currentPage]],components: [voteActions],});};if(i.customId===`${nameLower}-smash`){updateSQL=`UPDATE MOBILE_WEAPONS SET SMASHES = SMASHES + 1 WHERE NAME = ?`;db.run(updateSQL,[nameLower],function(err){if(err){returnconsole.error(err.message);}});awaiti.update({content: "You voted smash!",embeds: [resultsEmbed.addFields({name: "🟢 Smashes",value: `${smashes+1}`,inline: true,},{name: "🔴 Passes",value: `${passes}`,inline: true,},)],components: [],});collector.stop("smashed");}elseif(i.customId===`${nameLower}-pass`){updateSQL=`UPDATE MOBILE_WEAPONS SET PASSES = PASSES + 1 WHERE NAME = ?`;db.run(updateSQL,[nameLower],function(err){if(err){returnconsole.error(err.message);}});awaiti.update({content: "You voted pass!",embeds: [resultsEmbed.addFields({name: "🟢 Smashes",value: `${smashes}`,inline: true,},{name: "🔴 Passes",value: `${passes+1}`,inline: true,},)],components: [],});collector.stop("passed");}collector.on('end',()=>interaction.editReply({content: 'Game Over!',components: []})&&console.log("stopped"));});});},};
variable-formation
changed the title
I assumed it would have just taken the emoji out of the message and only returned that emoji? https://eu8.fastcast4u.com/proxy/pacormn?mp=/1 The feature isn't in the API yet maybe ill try reinvite it Thanks for the catch. Image discord.js is for bots For a web dashboard, you should just use @discordjs/rest and discord-api-types for your server side Collector#end not firing off unless there's been another button pressed.
Collector#end not firing off unless there's been another button pressed.
Nov 4, 2023
Jiralite
changed the title
Collector#end not firing off unless there's been another button pressed.
I assumed it would have just taken the emoji out of the message and only returned that emoji?
Nov 4, 2023
variable-formation
changed the title
I assumed it would have just taken the emoji out of the message and only returned that emoji?
Collector#end not firing off unless there's been another button pressed.
Nov 4, 2023
You nested your listener, so it will not register until something reaches it. This is not a bug.
Please don't dump your file and expect someone to comb through it to find your issue. You should provide a minimal reproducible code sample—whilst doing that, you may even find your issue.
Which package is this bug report for?
discord.js
Issue description
Steps to reproduce:
Collection.stop() works perfectly fine provided there is pagination input. But if someone presses smash or pass without paginating then it does not fire off.
Code sample
Versions
discord.js 14.13.0
Node.js v21.0.0
WSL 1.2.5.0 // Ubuntu 22.04.3 LTS
Issue priority
Low (slightly annoying)
Which partials do you have configured?
Not applicable
Which gateway intents are you subscribing to?
Guilds
I have tested this issue on a development release
No response
The text was updated successfully, but these errors were encountered: