Skip to content

Commit 950796f

Browse files
committed
added roleSelectMenu handler
1 parent 2144240 commit 950796f

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

src/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/events/interactionCreate.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ export default {
9191
console.log(error);
9292
}
9393
}
94+
95+
if (interaction.isRoleSelectMenu()) {
96+
const roleSelectMenu = client.roleSelectMenus.get(interaction.customId);
97+
if (!roleSelectMenu) return;
98+
try {
99+
roleSelectMenu.execute(client, interaction);
100+
} catch (error) {
101+
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
102+
console.log(error);
103+
}
104+
}
94105

95106
} catch (error) {
96107
return console.log(error);

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

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import buttonHandler from './handlers/buttons.js';
99
import stringSelectMenuHandler from './handlers/stringSelectMenus.js';
1010
import channelSelectMenuHandler from './handlers/channelSelectMenus.js';
1111
import mentionableSelectMenuHandler from './handlers/mentionableSelectMenus.js';
12+
import roleSelectMenuHandler from './handlers/roleSelectMenus.js';
1213
import contextMenus from './handlers/contextMenus.js';
1314
import register from './handlers/register.js';
1415

@@ -38,6 +39,7 @@ client.buttons = new Discord.Collection();
3839
client.stringSelectMenus = new Discord.Collection();
3940
client.channelSelectMenus = new Discord.Collection();
4041
client.mentionableSelectMenus = new Discord.Collection();
42+
client.roleSelectMenus = new Discord.Collection();
4143
client.contextMenus = new Discord.Collection();
4244

4345
await eventHandler.loadEvents(client);
@@ -48,6 +50,7 @@ await buttonHandler.loadButtons(client);
4850
await stringSelectMenuHandler.loadStringSelectMenus(client);
4951
await channelSelectMenuHandler.loadChannelSelectMenus(client);
5052
await mentionableSelectMenuHandler.loadMentionableSelectMenus(client);
53+
await roleSelectMenuHandler.loadRoleSelectMenus(client);
5154
await contextMenus.loadContextMenus(client);
5255
await register.load(client);
5356

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)