ReferenceError: interaction is not defined at Object.execute (/home/container/commands/recru.js:

My code :
23 Replies
d.js toolkit
d.js toolkit4mo 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!
REGARDE MON STATUT
My code
const { EmbedBuilder,TextInputBuilder, TextInputStyle, ButtonBuilder, ButtonStyle, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction } = require("discord.js")
const { cp } = require("fs")
const { idempotency } = require("parse")
const configss = require('../config.json')



module.exports = {
name: '86523recrutement',
execute(message) {
const embed = new EmbedBuilder()
.setTitle(`${configss.emoji} Recrutement`)
.setDescription(`Appuyez sur ce boutton pour ouvrir le formulaire de recrutement de Areo Official.`)
.setColor('#0099ff')

const button1 = new ButtonBuilder()
.setCustomId('recrutement1')
.setLabel('Recrutement')
.setStyle(ButtonStyle.Secondary)

const row = new ActionRowBuilder()
.addComponents(button1)

message.channel.send({embeds: [embed], components: [row]})


const filter = (interaction) => interaction.customId === 'recrutement1';
const collector = message.channel.createMessageComponentCollector({ filter, time: 15000 });
const { EmbedBuilder,TextInputBuilder, TextInputStyle, ButtonBuilder, ButtonStyle, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction } = require("discord.js")
const { cp } = require("fs")
const { idempotency } = require("parse")
const configss = require('../config.json')



module.exports = {
name: '86523recrutement',
execute(message) {
const embed = new EmbedBuilder()
.setTitle(`${configss.emoji} Recrutement`)
.setDescription(`Appuyez sur ce boutton pour ouvrir le formulaire de recrutement de Areo Official.`)
.setColor('#0099ff')

const button1 = new ButtonBuilder()
.setCustomId('recrutement1')
.setLabel('Recrutement')
.setStyle(ButtonStyle.Secondary)

const row = new ActionRowBuilder()
.addComponents(button1)

message.channel.send({embeds: [embed], components: [row]})


const filter = (interaction) => interaction.customId === 'recrutement1';
const collector = message.channel.createMessageComponentCollector({ filter, time: 15000 });
collector.on('collect', (interaction) => {
interaction.reply({ content: 'Tu as appuyé', ephemeral: true });
const modal = new ModalBuilder({
customId: 'recrutement',
title: 'Fiche Formulaire',
});
const Age = new TextInputBuilder({
customId: 'age',
label: 'Quel âge as-tu ?',
style: TextInputStyle.Short,
})

const idée = new TextInputBuilder({
custom_id: 'idee',
label: 'As-tu des idées ?',
style: TextInputStyle.Paragraph
})

const ModalRow = new ActionRowBuilder().addComponents(Age)
const ModalRow2 = new ActionRowBuilder().addComponents(idée)


modal.addComponents(ModalRow, ModalRow2)
interaction.showModal(modal);


// Si j'ai bine compris sa devrai envoye le modal ??

});

const filte1r = (interaction) => interaction.customId === 'recrutement';
interaction
.awaitModalSubmit({filte1r, time: 30_000})
.then((ModalInteraction) => {
const Agevalue = ModalInteraction.fields.getTextInputValue('age');
const ideevalue = ModalInteraction.fields.getTextInputValue('idée');

ModalInteraction.reply(`Tu as ${Agevalue}`)

})
.catch((err) => {
console.log(`ERROR: ${err}`);
})
},
}
collector.on('collect', (interaction) => {
interaction.reply({ content: 'Tu as appuyé', ephemeral: true });
const modal = new ModalBuilder({
customId: 'recrutement',
title: 'Fiche Formulaire',
});
const Age = new TextInputBuilder({
customId: 'age',
label: 'Quel âge as-tu ?',
style: TextInputStyle.Short,
})

const idée = new TextInputBuilder({
custom_id: 'idee',
label: 'As-tu des idées ?',
style: TextInputStyle.Paragraph
})

const ModalRow = new ActionRowBuilder().addComponents(Age)
const ModalRow2 = new ActionRowBuilder().addComponents(idée)


modal.addComponents(ModalRow, ModalRow2)
interaction.showModal(modal);


// Si j'ai bine compris sa devrai envoye le modal ??

});

const filte1r = (interaction) => interaction.customId === 'recrutement';
interaction
.awaitModalSubmit({filte1r, time: 30_000})
.then((ModalInteraction) => {
const Agevalue = ModalInteraction.fields.getTextInputValue('age');
const ideevalue = ModalInteraction.fields.getTextInputValue('idée');

ModalInteraction.reply(`Tu as ${Agevalue}`)

})
.catch((err) => {
console.log(`ERROR: ${err}`);
})
},
}
I can't find how to define interaction
mallusrgreat
mallusrgreat4mo ago
interaction .awaitModalSubmit({filte1r, time: 30_000})
where is interaction defined there is no interaction defined here did you mean to put it inside the collect event
REGARDE MON STATUT
? where ?
probablyraging
probablyraging4mo ago
No description
REGARDE MON STATUT
yse but what should I do to define it
probablyraging
probablyraging4mo ago
Move it inside the scope of where it's defined?
REGARDE MON STATUT
but isn't defined
probablyraging
probablyraging4mo ago
Show me where it's defined
REGARDE MON STATUT
is not edfined
probablyraging
probablyraging4mo ago
It is, in your collector
REGARDE MON STATUT
And how
probablyraging
probablyraging4mo ago
How what?
REGARDE MON STATUT
How define this
probablyraging
probablyraging4mo ago
You've already defined interaction, but you are trying to access it outside of the scope of where you defined it, you just need to move your code inside of the scope where it's already defined
REGARDE MON STATUT
But he tells me it's not defined
probablyraging
probablyraging4mo ago
Because you're trying to access it outside of the scope of where you've defined it
ahmood
ahmood4mo ago
just put the awaitModalSubmit part inside the collector, its not that complicated also await the await interaciton.showModal()
REGARDE MON STATUT
ok i try it no
const { EmbedBuilder,TextInputBuilder, TextInputStyle, ButtonBuilder, ButtonStyle, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction } = require("discord.js")
const { cp } = require("fs")
const { idempotency } = require("parse")



module.exports = {
name: 'recrutement',
execute(message) {
const embed = new EmbedBuilder()
.setTitle(`{config.emoji} Recrutement`)
.setDescription(`Appuyez sur ce boutton pour ouvrir le formulaire de rerutement de areo`)
.setColor('#0099ff')

const button1 = new ButtonBuilder()
.setCustomId('recrutement1')
.setLabel('Recrutement')
.setStyle(ButtonStyle.Secondary)

const row = new ActionRowBuilder()
.addComponents(button1)

message.channel.send({embeds: [embed], components: [row]})


const filter = (interaction) => interaction.customId === 'recrutement1';
const collector = message.channel.createMessageComponentCollector({ filter, time: 15000 });

collector.on('collect', async (interaction) => {
interaction.reply({ content: 'Tu as appuyé', ephemeral: true });
const modal = new ModalBuilder({
customId: 'recrutement',
title: ' 123',
});
const Age = new TextInputBuilder({
customId: 'age',
label: 'Quel age as-tu ?',
style: TextInputStyle.Short,
})

const idée = new TextInputBuilder({
custom_id: 'idee',
label: 'As-tu des idées ?',
style: TextInputStyle.Paragraph
})

const { EmbedBuilder,TextInputBuilder, TextInputStyle, ButtonBuilder, ButtonStyle, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction } = require("discord.js")
const { cp } = require("fs")
const { idempotency } = require("parse")



module.exports = {
name: 'recrutement',
execute(message) {
const embed = new EmbedBuilder()
.setTitle(`{config.emoji} Recrutement`)
.setDescription(`Appuyez sur ce boutton pour ouvrir le formulaire de rerutement de areo`)
.setColor('#0099ff')

const button1 = new ButtonBuilder()
.setCustomId('recrutement1')
.setLabel('Recrutement')
.setStyle(ButtonStyle.Secondary)

const row = new ActionRowBuilder()
.addComponents(button1)

message.channel.send({embeds: [embed], components: [row]})


const filter = (interaction) => interaction.customId === 'recrutement1';
const collector = message.channel.createMessageComponentCollector({ filter, time: 15000 });

collector.on('collect', async (interaction) => {
interaction.reply({ content: 'Tu as appuyé', ephemeral: true });
const modal = new ModalBuilder({
customId: 'recrutement',
title: ' 123',
});
const Age = new TextInputBuilder({
customId: 'age',
label: 'Quel age as-tu ?',
style: TextInputStyle.Short,
})

const idée = new TextInputBuilder({
custom_id: 'idee',
label: 'As-tu des idées ?',
style: TextInputStyle.Paragraph
})

const ModalRow = new ActionRowBuilder().addComponents(Age)
const ModalRow2 = new ActionRowBuilder().addComponents(idée)


modal.addComponents(ModalRow, ModalRow2)
await interaction.showModal(modal);



});

const filte1r = (interaction) => interaction.customId === 'recrutement';
interaction
.awaitModalSubmit({filte1r, time: 30_000})
.then((ModalInteraction) => {
const Agevalue = ModalInteraction.fields.getTextInputValue('age');
const ideevalue = ModalInteraction.fields.getTextInputValue('idée');

ModalInteraction.reply(`Tu as ${Agevalue}`)

})
.catch((err) => {
console.log(`ERROR: ${err}`);
})
},
}
const ModalRow = new ActionRowBuilder().addComponents(Age)
const ModalRow2 = new ActionRowBuilder().addComponents(idée)


modal.addComponents(ModalRow, ModalRow2)
await interaction.showModal(modal);



});

const filte1r = (interaction) => interaction.customId === 'recrutement';
interaction
.awaitModalSubmit({filte1r, time: 30_000})
.then((ModalInteraction) => {
const Agevalue = ModalInteraction.fields.getTextInputValue('age');
const ideevalue = ModalInteraction.fields.getTextInputValue('idée');

ModalInteraction.reply(`Tu as ${Agevalue}`)

})
.catch((err) => {
console.log(`ERROR: ${err}`);
})
},
}
ReferenceError: interaction is not defined at Object.execute (/home/container/commands/recru.js:59:9)
REGARDE MON STATUT
error here
No description
REGARDE MON STATUT
I don't understand what you are saying no bruh