Skip to content

Commit b1bdeec

Browse files
committed
broight back selectMenu handler
1 parent 6dbea8a commit b1bdeec

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/events/interactionCreate.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export default {
5757
console.log(error);
5858
}
5959
}
60-
//TODO
6160

6261
if (interaction.isStringSelectMenu()) {
6362
const stringSelectMenu = client.stringSelectMenus.get(interaction.customId);

src/handlers/selectMenus.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { readdirSync } from 'fs';
2+
import chalk from 'chalk';
3+
4+
async function loadSelectMenus(client) {
5+
client.selectMenus.clear();
6+
let files = 0;
7+
const selectMenuFiles = readdirSync('./src/interactions/selectMenus').filter(file => file.endsWith('.js'));
8+
if (!client.selectMenus) return;
9+
for (let i = 0; i < selectMenuFiles.length; i++) {
10+
const selectMenu = await import(`../interactions/selectMenus/${selectMenuFiles[i]}?${Date.now()}`);
11+
await client.selectMenus.set(selectMenu.default.id, selectMenu.default);
12+
console.log(chalk.greenBright(`[selectMenu] Loaded ${(chalk.yellow(selectMenuFiles[i]))} with selectMenu ${(chalk.yellow(selectMenu.default.id))}`));
13+
files++;
14+
}
15+
const selectMenuFolders = readdirSync('./src/interactions/selectMenus', { withFileTypes: true }).filter(file => file.isDirectory());
16+
if (!selectMenuFolders) return;
17+
for (let i = 0; i < selectMenuFolders.length; i++) {
18+
const selectMenuFiles = readdirSync(`./src/interactions/selectMenus/${selectMenuFolders[i].name}`).filter(file => file.endsWith('.js'));
19+
for (let j = 0; j < selectMenuFiles.length; j++) {
20+
const selectMenu = await import(`../interactions/selectMenus/${selectMenuFolders[i].name}/${selectMenuFiles[j]}?${Date.now()}`);
21+
await client.selectMenus.set(selectMenu.default.id, selectMenu.default);
22+
console.log(chalk.greenBright(`[selectMenu] Loaded ${(chalk.yellow(selectMenuFiles[j]))} with selectMenu ${(chalk.yellow(selectMenu.default.id))}`));
23+
files++;
24+
}
25+
}
26+
return files;
27+
}
28+
29+
export default { loadSelectMenus };

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import messageCommandHandler from './handlers/messageCommands.js';
66
import slashCommandHandler from './handlers/slashCommands.js';
77
import modalHandler from './handlers/modals.js';
88
import buttonHandler from './handlers/buttons.js';
9+
import selectMenuHandler from './handlers/selectMenus.js';
910
import stringSelectMenuHandler from './handlers/stringSelectMenus.js';
1011
import channelSelectMenuHandler from './handlers/channelSelectMenus.js';
1112
import mentionableSelectMenuHandler from './handlers/mentionableSelectMenus.js';
@@ -37,6 +38,7 @@ client.messageCommandsAliases = new Discord.Collection();
3738
client.slashCommands = new Discord.Collection();
3839
client.modals = new Discord.Collection();
3940
client.buttons = new Discord.Collection();
41+
client.selectMenus = new Discord.Collection();
4042
client.stringSelectMenus = new Discord.Collection();
4143
client.channelSelectMenus = new Discord.Collection();
4244
client.mentionableSelectMenus = new Discord.Collection();
@@ -49,6 +51,7 @@ await messageCommandHandler.loadMessageCommands(client);
4951
await slashCommandHandler.loadSlashCommands(client);
5052
await modalHandler.loadModals(client);
5153
await buttonHandler.loadButtons(client);
54+
await selectMenuHandler.loadSelectMenus(client);
5255
await stringSelectMenuHandler.loadStringSelectMenus(client);
5356
await channelSelectMenuHandler.loadChannelSelectMenus(client);
5457
await mentionableSelectMenuHandler.loadMentionableSelectMenus(client);

0 commit comments

Comments
 (0)