Select menus not being able to be handled

Whenever I try to run my bot it just says "Cannot read properties of undefined (reading 'set')". handleComponents.js:
const { readdirSync } = require("fs");

module.exports = (client) => {
client.handleComponents = async () => {
const componentFolders = readdirSync(`./bot/components`);
for (const folder of componentFolders) {
const componentFiles = readdirSync(`./bot/components/${folder}`).filter(
(file) => file.endsWith(".js")
);

const { buttons, modals, selectMenus } = client;

switch (folder) {
case "buttons":
for (const file of componentFiles) {
const button = require(`../../components/${folder}/${file}`);
buttons.set(button.data.name, button);
}
break;

case "modals":
for (const file of componentFiles) {
const modal = require(`../../components/${folder}/${file}`);
modals.set(modal.data.name, modal);
}
break;

case "selectMenus":
for (const file of componentFiles) {
const menu = require(`../../components/${folder}/${file}`);
console.log(menu.data.name);
console.log(menu);
selectMenus.set(menu.data.name, menu);
}
break;

default:
break;
}
}
};
};
const { readdirSync } = require("fs");

module.exports = (client) => {
client.handleComponents = async () => {
const componentFolders = readdirSync(`./bot/components`);
for (const folder of componentFolders) {
const componentFiles = readdirSync(`./bot/components/${folder}`).filter(
(file) => file.endsWith(".js")
);

const { buttons, modals, selectMenus } = client;

switch (folder) {
case "buttons":
for (const file of componentFiles) {
const button = require(`../../components/${folder}/${file}`);
buttons.set(button.data.name, button);
}
break;

case "modals":
for (const file of componentFiles) {
const modal = require(`../../components/${folder}/${file}`);
modals.set(modal.data.name, modal);
}
break;

case "selectMenus":
for (const file of componentFiles) {
const menu = require(`../../components/${folder}/${file}`);
console.log(menu.data.name);
console.log(menu);
selectMenus.set(menu.data.name, menu);
}
break;

default:
break;
}
}
};
};
.../selectMenus/info.js:
const {
SlashCommandBuilder,
EmbedBuilder,
ButtonBuilder,
ActionRowBuilder,
ButtonStyle,
} = require("discord.js");
const { gamesArray } = require("../../commands/general/browse.js");

module.exports = {
data: {
name: "info",
},

async execute(interaction, client) {
const gameId = interaction.values[0];
const game = gamesArray.get(gameId);
const owner = await client.users.fetch(game.owner);
const embed = {
title: game.name,
description: game.description,
footer: { text: `Game ID: ${gameId}` },
author: {
name: owner.username,
iconURL: owner.displayAvatarURL(),
},
};
const play = new ButtonBuilder()
.setCustomId(`play,${gameId}`)
.setLabel(`Play`)
.setStyle(ButtonStyle.Success);
const report = new ButtonBuilder()
.setCustomId(`report,${gameId}`)
.setLabel(`Report`)
.setStyle(ButtonStyle.Danger);
interaction.update({
embeds: [embed],
components: [new ActionRowBuilder().addComponents(play, report)],
});
},
};
const {
SlashCommandBuilder,
EmbedBuilder,
ButtonBuilder,
ActionRowBuilder,
ButtonStyle,
} = require("discord.js");
const { gamesArray } = require("../../commands/general/browse.js");

module.exports = {
data: {
name: "info",
},

async execute(interaction, client) {
const gameId = interaction.values[0];
const game = gamesArray.get(gameId);
const owner = await client.users.fetch(game.owner);
const embed = {
title: game.name,
description: game.description,
footer: { text: `Game ID: ${gameId}` },
author: {
name: owner.username,
iconURL: owner.displayAvatarURL(),
},
};
const play = new ButtonBuilder()
.setCustomId(`play,${gameId}`)
.setLabel(`Play`)
.setStyle(ButtonStyle.Success);
const report = new ButtonBuilder()
.setCustomId(`report,${gameId}`)
.setLabel(`Report`)
.setStyle(ButtonStyle.Danger);
interaction.update({
embeds: [embed],
components: [new ActionRowBuilder().addComponents(play, report)],
});
},
};
Console:
$ node bot/bot.js
Started refreshing / commands.
info
{ data: { name: 'info' }, execute: [AsyncFunction: execute] }
C:\...\GitHub\StItch\bot\functions\handlers\handleComponents.js:33
selectMenus.set(menu.data.name, menu);
^

TypeError: Cannot read properties of undefined (reading 'set')
at client.handleComponents (C:\...\GitHub\StItch\bot\functions\handlers\handleComponents.js:33:25)
at Object.<anonymous> (C:\...\GitHub\StItch\bot\bot.js:38:8)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.12.1
$ node bot/bot.js
Started refreshing / commands.
info
{ data: { name: 'info' }, execute: [AsyncFunction: execute] }
C:\...\GitHub\StItch\bot\functions\handlers\handleComponents.js:33
selectMenus.set(menu.data.name, menu);
^

TypeError: Cannot read properties of undefined (reading 'set')
at client.handleComponents (C:\...\GitHub\StItch\bot\functions\handlers\handleComponents.js:33:25)
at Object.<anonymous> (C:\...\GitHub\StItch\bot\bot.js:38:8)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.12.1
The console is referring to this line:
selectMenus.set(menu.data.name, menu);
selectMenus.set(menu.data.name, menu);
2 Replies
d.js toolkit
d.js toolkit6mo 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! - Marked as resolved by OP
Inbestigator
Inbestigator6mo ago
Please ping That was it, I coulda sworn I defined it ty