Renzo
Renzo
DIAdiscord.js - Imagine an app
Created by Renzo on 12/24/2023 in #djs-questions
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
9 replies
DIAdiscord.js - Imagine an app
Created by Renzo on 12/13/2023 in #djs-questions
help with interaction
Hi! I'm new using discordjs, also learning to program. I have this piece of code where i wait for a StringSelect response from the user
let firstRoundRow = new ActionRowBuilder()
.setComponents(cardSelect)

let firstRoundEmbed = new EmbedBuilder()
.setTitle('Primera mano!')
.setColor('#FFDE33')
.setDescription(`${user} vs ${rival} jugando un trucardo`);

const round1response = await msgTable.reply(
{
content:`${rival} elige tu jugada:`,
components:[firstRoundRow],
embeds:[firstRoundEmbed]
}
);

const round1RivalInteraction = await round1response.awaitMessageComponent({ collectorRivalFilter, componentType: 3, time: 60000 });
let firstRoundRow = new ActionRowBuilder()
.setComponents(cardSelect)

let firstRoundEmbed = new EmbedBuilder()
.setTitle('Primera mano!')
.setColor('#FFDE33')
.setDescription(`${user} vs ${rival} jugando un trucardo`);

const round1response = await msgTable.reply(
{
content:`${rival} elige tu jugada:`,
components:[firstRoundRow],
embeds:[firstRoundEmbed]
}
);

const round1RivalInteraction = await round1response.awaitMessageComponent({ collectorRivalFilter, componentType: 3, time: 60000 });
cardSelect its a StringSelectMenuBuilder this interaction works well, it pass the next if block
if(round1RivalInteraction.values == 'envido'){ //first round envido

const envRow = new ActionRowBuilder()
.addComponents(envSelectResponse);

const userResponseMsg = await round1RivalInteraction.reply(
{
content:`${user} aceptas el ${round1RivalInteraction.values}`,
components:[envRow],
}
);

const userResponseEnv = await userResponseMsg.awaitMessageComponent({collectorUserFilter,componentType:3,time:60000});
if(round1RivalInteraction.values == 'envido'){ //first round envido

const envRow = new ActionRowBuilder()
.addComponents(envSelectResponse);

const userResponseMsg = await round1RivalInteraction.reply(
{
content:`${user} aceptas el ${round1RivalInteraction.values}`,
components:[envRow],
}
);

const userResponseEnv = await userResponseMsg.awaitMessageComponent({collectorUserFilter,componentType:3,time:60000});
envSelectResponse its a StringSelectMenuBuilder i dont know why when my code gets to the userResponseMsg and the user is supposed to interact with it (selecting the string option) i get a 'Failed interaction' i dont know if the problem is the collector, or if im using wrong the awaitMessageComponent method or idk 💀 im sorry if its a stupid question
16 replies