Inbestigator
Inbestigator
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Inbestigator on 1/1/2024 in #djs-questions
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);
5 replies
DIAdiscord.js - Imagine an app
Created by Inbestigator on 12/17/2023 in #djs-questions
Handle two buttons with one script
How can I make it so that if a user clicks button A with the id of infoDog it'll trigger the info handler, which will show info about dogs. When the user clicks button B with the id of infoCat, it'll trigger the same handler, and will show info about cats (must be infinitely expandable). Please ping for reply
4 replies
DIAdiscord.js - Imagine an app
Created by Inbestigator on 12/3/2023 in #djs-questions
Dynamically update command choices without using autocomplete
The title says it all, I don't want to have to use autocomplete as I've found it can be pretty buggy. I'd like to be able to do something like this:
const { gamesArray } = require("./browse.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Play a game.")
.addStringOption((option) =>
option
.setName("id")
.setDescription("The ID of the game to play.")
.setRequired(true)
.addChoices(...gamesArray)
),
const { gamesArray } = require("./browse.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Play a game.")
.addStringOption((option) =>
option
.setName("id")
.setDescription("The ID of the game to play.")
.setRequired(true)
.addChoices(...gamesArray)
),
but currently it just says "No options available" (gamesArray is formatted correctly)
24 replies
DIAdiscord.js - Imagine an app
Created by Inbestigator on 11/26/2023 in #djs-questions
Fetch emoji I don't have access to
(@ to reply) I was wondering if it's possible to fetch any emoji's name by it's ID. I'd like it to work even if the bot isn't in the server that the emoji is from.
17 replies
TIPThe Iris Project
Created by Inbestigator on 7/15/2023 in #iris-issues
All text boxes have an extra dark tint
No description
4 replies
DIAdiscord.js - Imagine an app
Created by Inbestigator on 5/26/2023 in #djs-questions
Voice chat join event detection and handling
Please god someone tell me how to respond accordingly to when a user enters a VC, the documentation is nonexistent and no one is talking about it on Stack Overflowed
3 replies