TypeError: Cannot read properties of undefined (reading 'id')

Hey, I want to make a setlan command for my bot, when it sends the embed, it seems that the collector collects something itsself and the bot gives a "wtf" reply. Can anyone help me fix it? DiscordJS version: 14.11.0 Code:
const { SlashCommandBuilder } = require("@discordjs/builders");
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ComponentType,
} = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("setlan")
.setDescription("Set Your Preferred Language!"),
async execute(interaction, client, profileData, language) {
const embed = new EmbedBuilder()
.setTitle(`${language.changing_language}`)
.setDescription(`> ${language.changing_language_description}`)
.setColor("#FFE700");
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("english")
.setLabel("English")
.setEmoji(":flag_gb:")
.setStyle("Primary"),
new ButtonBuilder()
.setCustomId("persian")
.setLabel("Persian")
.setEmoji(":flag_ir:")
.setStyle("Secondary"),
new ButtonBuilder()
.setCustomId("close_window")
.setLabel("Close window")
.setEmoji(":no_entry:")
.setStyle("Danger")
);
const collector = await interaction.channel.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
});

collector.on("collect", (i) => {
if (i.user.id === interaction.user.id) {
if (i.customId == "english") {
profileData.lang = "English";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"English"
)}`,
});
collector.stop();
} else if (i.customId == "persian") {
profileData.lang = "Persian";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"فارسی"
)}`,
});
collector.stop();
} else if (i.customId == "close_window") {
interaction.deleteReply();
i.deferUpdate();
collector.stop();
} else {
i.reply({ content: "wtf", ephemeral: true });
}
} else {
i.reply({
content: `${language.these_buttons_arent_for_you}`,
ephemeral: true,
});
}
});

collector.on("end", (collected) => {
row.components[0].setDisabled(true);
row.components[1].setDisabled(true);
row.components[2].setDisabled(true);
interaction.editReply({ embeds: [embed], components: [row] });
});
await interaction.reply({ embeds: [embed], components: [row] });
},
};
const { SlashCommandBuilder } = require("@discordjs/builders");
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ComponentType,
} = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("setlan")
.setDescription("Set Your Preferred Language!"),
async execute(interaction, client, profileData, language) {
const embed = new EmbedBuilder()
.setTitle(`${language.changing_language}`)
.setDescription(`> ${language.changing_language_description}`)
.setColor("#FFE700");
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("english")
.setLabel("English")
.setEmoji(":flag_gb:")
.setStyle("Primary"),
new ButtonBuilder()
.setCustomId("persian")
.setLabel("Persian")
.setEmoji(":flag_ir:")
.setStyle("Secondary"),
new ButtonBuilder()
.setCustomId("close_window")
.setLabel("Close window")
.setEmoji(":no_entry:")
.setStyle("Danger")
);
const collector = await interaction.channel.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
});

collector.on("collect", (i) => {
if (i.user.id === interaction.user.id) {
if (i.customId == "english") {
profileData.lang = "English";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"English"
)}`,
});
collector.stop();
} else if (i.customId == "persian") {
profileData.lang = "Persian";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"فارسی"
)}`,
});
collector.stop();
} else if (i.customId == "close_window") {
interaction.deleteReply();
i.deferUpdate();
collector.stop();
} else {
i.reply({ content: "wtf", ephemeral: true });
}
} else {
i.reply({
content: `${language.these_buttons_arent_for_you}`,
ephemeral: true,
});
}
});

collector.on("end", (collected) => {
row.components[0].setDisabled(true);
row.components[1].setDisabled(true);
row.components[2].setDisabled(true);
interaction.editReply({ embeds: [embed], components: [row] });
});
await interaction.reply({ embeds: [embed], components: [row] });
},
};
6 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Pooyan
PooyanOP2y ago
node version: 16.14.2
d.js docs
d.js docs2y ago
If you are waiting for button or select menu input from a specific message, don't create the collector on the channel. - Channel collectors return component interactions for any component within that channel.
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
Pooyan
PooyanOP2y ago
Full error:
TypeError: Cannot read properties of undefined (reading 'id')
at MessageCollector.<anonymous> (C:\PDM Team Bot\slashcommands\Config\setlan.js:40:18)
at MessageCollector.emit (node:events:526:28)
at MessageCollector.handleCollect (C:\PDM Team Bot\node_modules\discord.js\src\structures\interfaces\Collector.js:133:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) uncaughtException
TypeError: Cannot read properties of undefined (reading 'id')
at MessageCollector.<anonymous> (C:\PDM Team Bot\slashcommands\Config\setlan.js:40:18)
at MessageCollector.emit (node:events:526:28)
at MessageCollector.handleCollect (C:\PDM Team Bot\node_modules\discord.js\src\structures\interfaces\Collector.js:133:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) uncaughtException
TypeError: Cannot read properties of undefined (reading 'id')
at MessageCollector.<anonymous> (C:\PDM Team Bot\slashcommands\Config\setlan.js:40:18)
at MessageCollector.emit (node:events:526:28)
at MessageCollector.handleCollect (C:\PDM Team Bot\node_modules\discord.js\src\structures\interfaces\Collector.js:133:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) uncaughtException
TypeError: Cannot read properties of undefined (reading 'id')
at MessageCollector.<anonymous> (C:\PDM Team Bot\slashcommands\Config\setlan.js:40:18)
at MessageCollector.emit (node:events:526:28)
at MessageCollector.handleCollect (C:\PDM Team Bot\node_modules\discord.js\src\structures\interfaces\Collector.js:133:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) uncaughtException
so interaction.message or what? const message = interaction.reply(...) message.createMessageComponentCollector(...)?
treble/luna
treble/luna2y ago
pass in fetchReply : true to get the message (iirc)
Pooyan
PooyanOP2y ago
I Don't get it
await interaction.reply({
embeds: [embed],
components: [row],
fetchReply: true,
});
const message = interaction.fetchReply();
const collector = message.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
max: 2,
});
await interaction.reply({
embeds: [embed],
components: [row],
fetchReply: true,
});
const message = interaction.fetchReply();
const collector = message.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
max: 2,
});
This didn't work I didn't get it FakeSmile didn't work too No difference
await interaction.reply({
embeds: [embed],
components: [row],
fetchReply: true,
});
const message = await interaction.fetchReply();
const collector = message.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
max: 2,
});
await interaction.reply({
embeds: [embed],
components: [row],
fetchReply: true,
});
const message = await interaction.fetchReply();
const collector = message.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
max: 2,
});
Thanks Ariya
Want results from more Discord servers?
Add your server