Button message not working

I want when other users who arent the interaction user get met with this message 'only user can use these buttons', but this doesnt work.
const filter = (i) => i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 });

collector.on('collect', async (i) => {
try {
if (i.user.id !== interaction.user.id) {
// User is not the original user who triggered the command
await i.reply({ content: 'Only the user who triggered the command can use these buttons', ephemeral: true });
return;
}

if (i.customId === 'prev_page') {
if (currentPage > 0) {
currentPage--;
await updateEmbed();
}
} else if (i.customId === 'next_page') {
if (currentPage < totalPages - 1) {
currentPage++;
await updateEmbed();
}
}

// Acknowledge the interaction
await i.deferUpdate();
} catch (error) {
console.error(error);
}
});

collector.on('end', () => {
const disabledButtonRow = createButtonRow(currentPage, totalPages);
disabledButtonRow.components.forEach(button => button.setDisabled(true));
interaction.editReply({ components: [disabledButtonRow] });
});
}
} catch (e) {

const filter = (i) => i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 });

collector.on('collect', async (i) => {
try {
if (i.user.id !== interaction.user.id) {
// User is not the original user who triggered the command
await i.reply({ content: 'Only the user who triggered the command can use these buttons', ephemeral: true });
return;
}

if (i.customId === 'prev_page') {
if (currentPage > 0) {
currentPage--;
await updateEmbed();
}
} else if (i.customId === 'next_page') {
if (currentPage < totalPages - 1) {
currentPage++;
await updateEmbed();
}
}

// Acknowledge the interaction
await i.deferUpdate();
} catch (error) {
console.error(error);
}
});

collector.on('end', () => {
const disabledButtonRow = createButtonRow(currentPage, totalPages);
disabledButtonRow.components.forEach(button => button.setDisabled(true));
interaction.editReply({ components: [disabledButtonRow] });
});
}
} catch (e) {

3 Replies
d.js toolkit
d.js toolkit8mo 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!
mallusrgreat
mallusrgreat8mo ago
remove the filter you're already filtering out all the people who isn't the user of the original interaction
BakeWithMe
BakeWithMeOP8mo ago
oh okay i will try that thank you
Want results from more Discord servers?
Add your server