Limiting interaction to a specific user

Hi, I'm working with interaction that uses buttonbuilders. Is there some way to limit the interaction to a specific user?
let user = interaction.user;
let rival = interaction.options.getUser('friend');

const cortar = new ButtonBuilder()
.setCustomId('cortar')
.setStyle(ButtonStyle.Primary)
.setEmoji('🟢');

const nocortar = new ButtonBuilder()
.setCustomId('nocortar')
.setStyle(ButtonStyle.Primary)
.setEmoji('🔴');

const cortarRow = new ActionRowBuilder()
.addComponents(cortar,nocortar);

let rivalresponse = await interaction.reply({
content:`${rival}\nVas a cortar o no?\n`,
components : [cortarRow],
})

const collectorRivalFilter = (i) => i.user.id == rival.id;
const collectorUserFilter = (i) => i.user.id == user.id;

const cortarInteraction = await rivalresponse.awaitMessageComponent({ collectorRivalFilter, componentType: 2, time: 60000 });
const respCortar = cortarInteraction.customId;

if(respCortar == "cortar"){
game.startGame(true);
rivalresponse = await rivalresponse.edit({
content: "Cortamos la mano!",
components: []
});
}else{
game.startGame(false);
rivalresponse = await rivalresponse.edit({
content: "No cortamos la mano!",
components: []
})
}
let user = interaction.user;
let rival = interaction.options.getUser('friend');

const cortar = new ButtonBuilder()
.setCustomId('cortar')
.setStyle(ButtonStyle.Primary)
.setEmoji('🟢');

const nocortar = new ButtonBuilder()
.setCustomId('nocortar')
.setStyle(ButtonStyle.Primary)
.setEmoji('🔴');

const cortarRow = new ActionRowBuilder()
.addComponents(cortar,nocortar);

let rivalresponse = await interaction.reply({
content:`${rival}\nVas a cortar o no?\n`,
components : [cortarRow],
})

const collectorRivalFilter = (i) => i.user.id == rival.id;
const collectorUserFilter = (i) => i.user.id == user.id;

const cortarInteraction = await rivalresponse.awaitMessageComponent({ collectorRivalFilter, componentType: 2, time: 60000 });
const respCortar = cortarInteraction.customId;

if(respCortar == "cortar"){
game.startGame(true);
rivalresponse = await rivalresponse.edit({
content: "Cortamos la mano!",
components: []
});
}else{
game.startGame(false);
rivalresponse = await rivalresponse.edit({
content: "No cortamos la mano!",
components: []
})
}
Im using that collectors but it doesn't works the way I want
5 Replies
d.js toolkit
d.js toolkit•12mo 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! - ✅ Marked as resolved by OP
treble/luna
treble/luna•12mo ago
because you're not passing in a filter property you're passing a collecorRivalFilter
Renzo
RenzoOP•12mo ago
i'm sorry but I don't understand. What would be the correct way to do it then?
treble/luna
treble/luna•12mo ago
pass in a filter properly With the filter you want to pass
Renzo
RenzoOP•12mo ago
thanks! now it works sorry, that was a silly question
Want results from more Discord servers?
Add your server