Skip to content

Commit d0b80c6

Browse files
authored
Merge pull request #2 from BLACK4585/master
Added handlers for every Select Menu
2 parents 0a4367f + 035d350 commit d0b80c6

File tree

13 files changed

+251
-2
lines changed

13 files changed

+251
-2
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Simple and easy to use Slash Command Handler for Discord.js v14.
44

55
## Prerequisites
6-
- Node.js v20.0.0 or newer is required. You can download it [here](https://nodejs.org/en/download/).
6+
- Node.js v18.16.0 or newer is recommended. Older versions might work. You can download it [here](https://nodejs.org/en/download/).
77

88
## Installation
99
1. Fill out the `config.js.TEMPLATE` located in the `src/data` folder.
@@ -24,6 +24,10 @@ Category folders are optional, but you cant have a subfolder in a category.
2424
...
2525
```
2626

27+
## Select Menus
28+
In order to use select menus you can either put them all in ``/interactions/selectMenus`` or divided by their category in their according folder.
29+
Example: A user select menu would be in ``/interactions/userSelectMenus/example.js``
30+
2731
## Contributing
2832
Just make a pull request and I will review it.
2933

src/events/interactionCreate.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default {
4747
}
4848
}
4949

50-
if (interaction.isStringSelectMenu()) {
50+
if (interaction.isAnySelectMenu()) {
5151
const selectMenu = client.selectMenus.get(interaction.customId);
5252
if (!selectMenu) return;
5353
try {
@@ -57,6 +57,61 @@ export default {
5757
console.log(error);
5858
}
5959
}
60+
61+
if (interaction.isStringSelectMenu()) {
62+
const stringSelectMenu = client.stringSelectMenus.get(interaction.customId);
63+
if (!stringSelectMenu) return;
64+
try {
65+
stringSelectMenu.execute(client, interaction);
66+
} catch (error) {
67+
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
68+
console.log(error);
69+
}
70+
}
71+
72+
if (interaction.isChannelSelectMenu()) {
73+
const channelSelectMenu = client.channelSelectMenus.get(interaction.customId);
74+
if (!channelSelectMenu) return;
75+
try {
76+
channelSelectMenu.execute(client, interaction);
77+
} catch (error) {
78+
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
79+
console.log(error);
80+
}
81+
}
82+
83+
if (interaction.isMentionableSelectMenu()) {
84+
const mentionableSelectMenu = client.mentionableSelectMenus.get(interaction.customId);
85+
if (!mentionableSelectMenu) return;
86+
try {
87+
mentionableSelectMenu.execute(client, interaction);
88+
} catch (error) {
89+
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
90+
console.log(error);
91+
}
92+
}
93+
94+
if (interaction.isRoleSelectMenu()) {
95+
const roleSelectMenu = client.roleSelectMenus.get(interaction.customId);
96+
if (!roleSelectMenu) return;
97+
try {
98+
roleSelectMenu.execute(client, interaction);
99+
} catch (error) {
100+
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
101+
console.log(error);
102+
}
103+
}
104+
105+
if (interaction.isUserSelectMenu()) {
106+
const userSelectMenu = client.userSelectMenus.get(interaction.customId);
107+
if (!userSelectMenu) return;
108+
try {
109+
userSelectMenu.execute(client, interaction);
110+
} catch (error) {
111+
interaction.reply({ content: 'There was an error while executing this select menu!', ephemeral: true });
112+
console.log(error);
113+
}
114+
}
60115

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

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

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

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import slashCommandHandler from './handlers/slashCommands.js';
77
import modalHandler from './handlers/modals.js';
88
import buttonHandler from './handlers/buttons.js';
99
import selectMenuHandler from './handlers/selectMenus.js';
10+
import stringSelectMenuHandler from './handlers/stringSelectMenus.js';
11+
import channelSelectMenuHandler from './handlers/channelSelectMenus.js';
12+
import mentionableSelectMenuHandler from './handlers/mentionableSelectMenus.js';
13+
import roleSelectMenuHandler from './handlers/roleSelectMenus.js';
14+
import userSelectMenuHandler from './handlers/userSelectMenus.js';
1015
import contextMenus from './handlers/contextMenus.js';
1116
import register from './handlers/register.js';
1217

@@ -34,6 +39,11 @@ client.slashCommands = new Discord.Collection();
3439
client.modals = new Discord.Collection();
3540
client.buttons = new Discord.Collection();
3641
client.selectMenus = new Discord.Collection();
42+
client.stringSelectMenus = new Discord.Collection();
43+
client.channelSelectMenus = new Discord.Collection();
44+
client.mentionableSelectMenus = new Discord.Collection();
45+
client.roleSelectMenus = new Discord.Collection();
46+
client.userSelectMenus = new Discord.Collection();
3747
client.contextMenus = new Discord.Collection();
3848

3949
await eventHandler.loadEvents(client);
@@ -42,6 +52,11 @@ await slashCommandHandler.loadSlashCommands(client);
4252
await modalHandler.loadModals(client);
4353
await buttonHandler.loadButtons(client);
4454
await selectMenuHandler.loadSelectMenus(client);
55+
await stringSelectMenuHandler.loadStringSelectMenus(client);
56+
await channelSelectMenuHandler.loadChannelSelectMenus(client);
57+
await mentionableSelectMenuHandler.loadMentionableSelectMenus(client);
58+
await roleSelectMenuHandler.loadRoleSelectMenus(client);
59+
await userSelectMenuHandler.loadUserSelectMenus(client);
4560
await contextMenus.loadContextMenus(client);
4661
await register.load(client);
4762

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+
};
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)