Interaction Collector Not Firing Collect

I'm trying to implement some buttons on a command interaction, and I have successfully added the buttons, but when creating a message component collector, the 'collect' callback is not being called. I'm creating it as follows:
await interaction.editReply({
content: `Post \`${post.postId}\` Edits`,
embeds: [editEmbed],
components: [buttonActionRow]
});

const collector = interaction.channel?.createMessageComponentCollector({
filter: (submit) =>
submit.customId === 'createPost' &&
submit.user.id === interaction.user.id,
time: 300_000
});
await interaction.editReply({
content: `Post \`${post.postId}\` Edits`,
embeds: [editEmbed],
components: [buttonActionRow]
});

const collector = interaction.channel?.createMessageComponentCollector({
filter: (submit) =>
submit.customId === 'createPost' &&
submit.user.id === interaction.user.id,
time: 300_000
});
Am I missing something here?
8 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
wen
wen2y ago
how do u know it's not being called ? also you're not calling it as i can see in the code provided u have just created the collector
_Rob
_RobOP2y ago
A) yes B) Because channel is optional according to the typings C) one sec I have a log in there
wen
wen2y ago
show the part where you listen to it
_Rob
_RobOP2y ago
collector?.on('collect', async (interaction: Discord.ButtonInteraction) => {
console.debug(interaction);
})
collector?.on('collect', async (interaction: Discord.ButtonInteraction) => {
console.debug(interaction);
})
It does exist, I did verify that Ah, ok
d.js docs
d.js docs2y ago
If you are waiting for button or select menu input from a specific message, don't create the collector on the channel. • Channel collectors return component interactions for any component within that channel.
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
wen
wen2y ago
yeah also better to create it on the message to avoid memory leaks
_Rob
_RobOP2y ago
Makes sense That will also get rid of the optionality of the collector Still doesn't seem to be working. Let me get a more complete code example.
export const postChangeLogInteractionHandler = async (
interaction: Discord.ChatInputCommandInteraction
) => {
const reply = await interaction.deferReply({
ephemeral: true,
fetchReply: true
});

// ... do async stuff

const backButton = new Discord.ButtonBuilder()
.setCustomId('back')
.setLabel('Back')
.setStyle(Discord.ButtonStyle.Primary);

const nextButton = new Discord.ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(Discord.ButtonStyle.Primary);

const buttonActionRow =
new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents(
backButton.setDisabled(currentIndex == 0),
nextButton.setDisabled(currentIndex === postEdits.length - 1)
);

await interaction.editReply({
content: `Post \`${post.postId}\` Edits`,
embeds: [editEmbed],
components: [buttonActionRow]
});

const collector = reply.createMessageComponentCollector({
filter: (submit) =>
submit.customId === 'createPost' &&
submit.user.id === interaction.user.id,
time: 300_000
});

collector.on('collect', async (interaction) => {
console.debug(interaction);
});
};
export const postChangeLogInteractionHandler = async (
interaction: Discord.ChatInputCommandInteraction
) => {
const reply = await interaction.deferReply({
ephemeral: true,
fetchReply: true
});

// ... do async stuff

const backButton = new Discord.ButtonBuilder()
.setCustomId('back')
.setLabel('Back')
.setStyle(Discord.ButtonStyle.Primary);

const nextButton = new Discord.ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(Discord.ButtonStyle.Primary);

const buttonActionRow =
new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents(
backButton.setDisabled(currentIndex == 0),
nextButton.setDisabled(currentIndex === postEdits.length - 1)
);

await interaction.editReply({
content: `Post \`${post.postId}\` Edits`,
embeds: [editEmbed],
components: [buttonActionRow]
});

const collector = reply.createMessageComponentCollector({
filter: (submit) =>
submit.customId === 'createPost' &&
submit.user.id === interaction.user.id,
time: 300_000
});

collector.on('collect', async (interaction) => {
console.debug(interaction);
});
};
Ah, yea, sorry Updated code facepalmpicard paste error on my part That fixed it. Thanks for helping me out
Want results from more Discord servers?
Add your server