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
10 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!
Ashish
Ashish•12mo ago
Are there any errors in your console?
kin.ts
kin.ts•12mo ago
array will never equal to string, use round1RivalInteraction.values[0] == 'envido'
Renzo
RenzoOP•12mo ago
Hi, no i dont get any error in console the code gets inside the if block, if i put a console.log before the userResponseEnv the console.log runs, but it doesnt run after the userResponseEnv, its like it get stucked in that line
Ashish
Ashish•12mo ago
Yeah, what kin said then, I missed that part as well
kin.ts
kin.ts•12mo ago
show ur latest code
Ashish
Ashish•12mo ago
Actually since they're not using the strict equality operator, ["value"] will be equal to "value"
Renzo
RenzoOP•12mo ago
const msgTable = await game.showTable(interaction);

await game.sendCardsTo(user, game.user);
await game.sendCardsTo(rival, game.rival);

let cardSelect = new StringSelectMenuBuilder()
.setCustomId('starter')
.setPlaceholder('Make a selection!')
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel('Primera carta')
.setValue('0'),
new StringSelectMenuOptionBuilder()
.setLabel('Segunda carta')
.setValue('1'),
new StringSelectMenuOptionBuilder()
.setLabel('Tercera carta')
.setValue('2'),
new StringSelectMenuOptionBuilder()
.setLabel('Envido')
.setValue('envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Real envido')
.setValue('real envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Falta envido')
.setValue('falta envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Truco')
.setValue('truco'),
new StringSelectMenuOptionBuilder()
.setLabel('Salir')
.setValue('salir'),
);

let firstRoundRow = new ActionRowBuilder()
.setComponents(cardSelect)

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

await game.sendCardsTo(user, game.user);
await game.sendCardsTo(rival, game.rival);

let cardSelect = new StringSelectMenuBuilder()
.setCustomId('starter')
.setPlaceholder('Make a selection!')
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel('Primera carta')
.setValue('0'),
new StringSelectMenuOptionBuilder()
.setLabel('Segunda carta')
.setValue('1'),
new StringSelectMenuOptionBuilder()
.setLabel('Tercera carta')
.setValue('2'),
new StringSelectMenuOptionBuilder()
.setLabel('Envido')
.setValue('envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Real envido')
.setValue('real envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Falta envido')
.setValue('falta envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Truco')
.setValue('truco'),
new StringSelectMenuOptionBuilder()
.setLabel('Salir')
.setValue('salir'),
);

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 });

const envSelectResponse= new StringSelectMenuBuilder()
.setCustomId('envResp')
.setPlaceholder('Select your response!')
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel('Acepto')
.setValue('acepto'),
new StringSelectMenuOptionBuilder()
.setLabel('No acepto')
.setValue('rechazo'),
new StringSelectMenuOptionBuilder()
.setLabel('Envido')
.setValue('envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Real envido')
.setValue('real envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Falta envido')
.setValue('falta envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Salir')
.setValue('salir'),
);

if(round1RivalInteraction.values[0] == 'envido'){ //first round envido

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

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

const userResponseEnv = await userResponseMsg.awaitMessageComponent({collectorUserFilter,componentType:3,time:60000});//here is where it gets stucked

if(userResponseEnv.values[0] == 'acepto' ){
game.playEnvido(true);
}else if(userResponseEnv.values[0] == 'rechazo'){
game.playEnvido(false);
}else if(userResponseEnv.values[0] == 'envido'){ //envido envido

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

const round1RivalInteraction = await round1response.awaitMessageComponent({ collectorRivalFilter, componentType: 3, time: 60000 });

const envSelectResponse= new StringSelectMenuBuilder()
.setCustomId('envResp')
.setPlaceholder('Select your response!')
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel('Acepto')
.setValue('acepto'),
new StringSelectMenuOptionBuilder()
.setLabel('No acepto')
.setValue('rechazo'),
new StringSelectMenuOptionBuilder()
.setLabel('Envido')
.setValue('envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Real envido')
.setValue('real envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Falta envido')
.setValue('falta envido'),
new StringSelectMenuOptionBuilder()
.setLabel('Salir')
.setValue('salir'),
);

if(round1RivalInteraction.values[0] == 'envido'){ //first round envido

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

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

const userResponseEnv = await userResponseMsg.awaitMessageComponent({collectorUserFilter,componentType:3,time:60000});//here is where it gets stucked

if(userResponseEnv.values[0] == 'acepto' ){
game.playEnvido(true);
}else if(userResponseEnv.values[0] == 'rechazo'){
game.playEnvido(false);
}else if(userResponseEnv.values[0] == 'envido'){ //envido envido

const envRow2 = new ActionRowBuilder()
This is the piece of code I'm having trouble with kin
Ashish
Ashish•12mo ago
When do you actually get the 'Failed interaction' msg? When you send: - ${rival} elige tu jugada: - or ${user} aceptas el ${round1RivalInteraction.values} ?
Renzo
RenzoOP•12mo ago
${user} aceptas el ${round1RivalInteraction.values} Here is where i get the 'Failed interaction' I made it work, I just edited the round1response message I added this before the if block
const prueba = await round1response.edit({
content:`${rival} seleccionó ...`,
components:[],
embeds:[]
}) //this is what i added

if(round1RivalInteraction.values[0] == 'envido'){ //first round envido

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

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

const userResponseEnv = await userResponseMsg.awaitMessageComponent({collectorUserFilter,componentType:3,time:60000}); //now works

if(userResponseEnv.values[0] == 'acepto' ){
game.playEnvido(true);
}else if(userResponseEnv.values[0] == 'rechazo'){
game.playEnvido(false);
}else if(userResponseEnv.values[0] == 'envido'){ //envido envido
const prueba = await round1response.edit({
content:`${rival} seleccionó ...`,
components:[],
embeds:[]
}) //this is what i added

if(round1RivalInteraction.values[0] == 'envido'){ //first round envido

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

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

const userResponseEnv = await userResponseMsg.awaitMessageComponent({collectorUserFilter,componentType:3,time:60000}); //now works

if(userResponseEnv.values[0] == 'acepto' ){
game.playEnvido(true);
}else if(userResponseEnv.values[0] == 'rechazo'){
game.playEnvido(false);
}else if(userResponseEnv.values[0] == 'envido'){ //envido envido
now I have a question, its necessary to edit the msg after getting a response from the user with the string select menu? thanks!!!
Want results from more Discord servers?
Add your server