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

My code :
23 Replies
d.js toolkit
d.js toolkit13mo 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!
./u.7-z
./u.7-zOP13mo ago
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
mallusrgreat13mo 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
./u.7-z
./u.7-zOP13mo ago
? where ?
zevnda
zevnda13mo ago
No description
./u.7-z
./u.7-zOP13mo ago
yse but what should I do to define it
zevnda
zevnda13mo ago
Move it inside the scope of where it's defined?
./u.7-z
./u.7-zOP13mo ago
but isn't defined
zevnda
zevnda13mo ago
Show me where it's defined
./u.7-z
./u.7-zOP13mo ago
is not edfined
zevnda
zevnda13mo ago
It is, in your collector
./u.7-z
./u.7-zOP13mo ago
And how
zevnda
zevnda13mo ago
How what?
./u.7-z
./u.7-zOP13mo ago
How define this
zevnda
zevnda13mo 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
./u.7-z
./u.7-zOP13mo ago
But he tells me it's not defined
zevnda
zevnda13mo ago
Because you're trying to access it outside of the scope of where you've defined it
./u.7-z
./u.7-zOP13mo ago
./u.7-z
./u.7-zOP13mo ago
No description
ahmood
ahmood13mo ago
just put the awaitModalSubmit part inside the collector, its not that complicated also await the await interaciton.showModal()
./u.7-z
./u.7-zOP13mo ago
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)
./u.7-z
./u.7-zOP13mo ago
error here
No description
./u.7-z
./u.7-zOP13mo ago
I don't understand what you are saying no bruh

Did you find this page helpful?