Skip to content

Commit 62f1d6b

Browse files
committed
added channelSelectMenu handler
1 parent d0c9aa9 commit 62f1d6b

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/events/interactionCreate.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ export default {
6363
const stringSelectMenu = client.stringSelectMenus.get(interaction.customId);
6464
if (!stringSelectMenu) return;
6565
try {
66-
tringS.execute(client, interaction);
66+
stringSelectMenu.execute(client, interaction);
67+
} catch (error) {
68+
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
69+
console.log(error);
70+
}
71+
}
72+
73+
if (interaction.isChannelSelectMenu()) {
74+
const channelSelectMenu = client.channelSelectMenus.get(interaction.customId);
75+
if (!channelSelectMenu) return;
76+
try {
77+
channelSelectMenu.execute(client, interaction);
6778
} catch (error) {
6879
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
6980
console.log(error);

src/handlers/channelSelectMenus.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 loadChannelSelectMenus(client) {
5+
client.channelSelectMenus.clear();
6+
let files = 0;
7+
const channelSelectMenuFiles = readdirSync('./src/interactions/channelSelectMenus').filter(file => file.endsWith('.js'));
8+
if (!client.channelSelectMenus) return;
9+
for (let i = 0; i < channelSelectMenuFiles.length; i++) {
10+
const channelSelectMenu = await import(`../interactions/channelSelectMenus/${channelSelectMenuFiles[i]}?${Date.now()}`);
11+
await client.channelSelectMenus.set(channelSelectMenu.default.id, channelSelectMenu.default);
12+
console.log(chalk.greenBright(`[channelSelectMenu] Loaded ${(chalk.yellow(channelSelectMenuFiles[i]))} with channelSelectMenu ${(chalk.yellow(channelSelectMenu.default.id))}`));
13+
files++;
14+
}
15+
const channelSelectMenuFolders = readdirSync('./src/interactions/channelSelectMenus', { withFileTypes: true }).filter(file => file.isDirectory());
16+
if (!channelSelectMenuFolders) return;
17+
for (let i = 0; i < channelSelectMenuFolders.length; i++) {
18+
const channelSelectMenuFiles = readdirSync(`./src/interactions/channelSelectMenus/${channelSelectMenuFolders[i].name}`).filter(file => file.endsWith('.js'));
19+
for (let j = 0; j < channelSelectMenuFiles.length; j++) {
20+
const channelSelectMenu = await import(`../interactions/channelSelectMenus/${selectMenuFolders[i].name}/${selectMenuFiles[j]}?${Date.now()}`);
21+
await client.channelSelectMenus.set(channelSelectMenu.default.id, channelSelectMenu.default);
22+
console.log(chalk.greenBright(`[channelSelectMenu] Loaded ${(chalk.yellow(channelSelectMenuFiles[j]))} with channelSelectMenu ${(chalk.yellow(channelSelectMenu.default.id))}`));
23+
files++;
24+
}
25+
}
26+
return files;
27+
}
28+
29+
export default { loadChannelSelectMenus };

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import slashCommandHandler from './handlers/slashCommands.js';
77
import modalHandler from './handlers/modals.js';
88
import buttonHandler from './handlers/buttons.js';
99
import stringSelectMenuHandler from './handlers/stringSelectMenus.js';
10+
import channelSelectMenuHandler from './handlers/channelSelectMenus.js';
1011
import contextMenus from './handlers/contextMenus.js';
1112
import register from './handlers/register.js';
1213

@@ -34,6 +35,7 @@ client.slashCommands = new Discord.Collection();
3435
client.modals = new Discord.Collection();
3536
client.buttons = new Discord.Collection();
3637
client.stringSelectMenus = new Discord.Collection();
38+
client.channelSelectMenus = new Discord.Collection();
3739
client.contextMenus = new Discord.Collection();
3840

3941
await eventHandler.loadEvents(client);
@@ -42,6 +44,7 @@ await slashCommandHandler.loadSlashCommands(client);
4244
await modalHandler.loadModals(client);
4345
await buttonHandler.loadButtons(client);
4446
await stringSelectMenuHandler.loadStringSelectMenus(client);
47+
await channelSelectMenuHandler.loadChannelSelectMenus(client);
4548
await contextMenus.loadContextMenus(client);
4649
await register.load(client);
4750

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
id: 'test',
3+
async execute(client, interaction) {
4+
interaction.reply('Hello World!');
5+
}
6+
};

0 commit comments

Comments
 (0)