#Filter of collectors do not work

16 messages · Page 1 of 1 (latest)

reef mortar
#

Hi,
I have a problem with filter of the collectors:
When I apply a filter it does not take in charge.
Here is an example :

const filter = e => e.message.id == interaction.message.id && e.user.id == interaction.user.id
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000, max: 1 });
collect.on('collect', async i => {
console.log(`Allowed user`)
})

This code should allow only the author of the slash command to trigger the collector and the console.log, except that any user can do it, the filter does not work.
Is this a discordjs issue?

vague spadeBOT
#

• 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.

reef mortar
#

Filter of collectors do not work

lucid bay
#

How did you determine any user can? And what is interaction defined as?

reef mortar
lucid bay
#

Show the full context/code

reef mortar
#
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionsBitField, PermissionFlagsBits, Discord } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
    .setName('gerer-item')
    .setDescription('Gerer un item')
    .addStringOption(option => option.setName('item').setDescription(`Item à gérer`).setAutocomplete(true).setRequired(true))
    .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),
async execute(interaction) {
// I didn't put it here but creation of the prem embed and ez components
interaction.reply({ embeds: [prem], components: [ez] })
   const filter = e => e.message.id == interaction.message.id &&
 e.user.id == interaction.user.id

const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000, max: 1 });

collector.on('collect', async i => {
    i.deferUpdate()
console.log(`the user can click on the buttton`)
//continuation of the code
})
}

And the problem is that any user initiates the action of the collector, whereas only the author of the slash command should be able to do so.

lucid bay
#

Also:

left elbowBOT
#

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(…)
reef mortar
lucid bay
#

So you also used the slashcommand? Seems like it works as it should

reef mortar
#

In this case, yes, except that if I'm the one doing the slash command, and it's someone else who click, the collector will work despite filter

lucid bay
#

Then show the log of one of those cases. No use in trying to debug one case but show the logs of a different case

reef mortar
#

Here are the logs when I did the slash command and someone else click on button

lucid bay