Skip to content

Commit

Permalink
⚡ | Select Menus Handler & Default Message"
Browse files Browse the repository at this point in the history
  • Loading branch information
NamVr committed Aug 28, 2021
1 parent 6ae06b2 commit 08e53ac
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ This template comes in with many in-built useful and flexible features, such as
- **IMPORTANT:** In the template, we are sending the slash commands to discord to be registered only to 1 guild. That is because their are 2 types of slash commands, guild and global. Guild commands are restricted to 1 guild but whenever you update them, they take effect immediately, whereas global commands take upto 1 hour to take effect. So use guild commands in development and global commands for production.

#### **[NEW] Dynamic Buttons Interaction Handler:**

- This template comes with a dynamic button interaction handler to receive and process button interactions.
- Buttons can be classified in two category folders.

#### **[NEW] Dynamic Context Menu Handler:**
- All new addition to discord API is context menus! You can right click a user or message -> Apps to find these options!

- All new addition to discord API is context menus! You can right click a user or message -> Apps to find these options!
- This template will register all your context menu options and dynamically interact with them! Worth a try.

#### **Highly Customizable:**
Expand Down
1 change: 1 addition & 0 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ for (const file of eventFiles) {
client.commands = new Collection();
client.slashCommands = new Collection();
client.buttonCommands = new Collection();
client.selectCommands = new Collection();
client.contextCommands = new Collection();
client.cooldowns = new Collection();
client.triggers = new Collection();
Expand Down
52 changes: 52 additions & 0 deletions events/selectInteraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file Select Menu Interaction Handler
* @author Naman Vrati
* @since 3.0.0
*/

module.exports = {
name: "interactionCreate",

/**
* @description Executes when an interaction is created and handle it.
* @author Naman Vrati
* @param {Object} interaction The interaction which was created
*/

async execute(interaction) {
// Deconstructed client from interaction object.
const { client } = interaction;

// Checks if the interaction is a select menu interaction (to prevent weird bugs)

if (!interaction.isSelectMenu()) return;
/**
* @description The Interaction command object
* @type {Object}
*/

const command = client.selectCommands.get(interaction.customId);

// If the interaction is not a command in cache, return error message.
// You can modify the error message at ./messages/defaultSelectError.js file!

if (!command) {
await require("../messages/defaultSelectError").execute(interaction);
return;
}

// A try to execute the interaction.

try {
await command.execute(interaction);
return;
} catch (err) {
console.error(err);
await interaction.reply({
content: "There was an issue while executing that select menu option!",
ephemeral: true,
});
return;
}
},
};
22 changes: 22 additions & 0 deletions interactions/select-menus/category/sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file Sample Select-Menu interaction
* @author Naman Vrati
* @since 3.0.0
*/

module.exports = {
id: "sample",

/**
* @description Executes when a select menu option with ID "sample" is clicked.
* @author Naman Vrati
* @param {Object} interaction The Interaction Object of the command.
*/

async execute(interaction) {
await interaction.reply({
content: "This was a reply from select menu handler!",
});
return;
},
};
21 changes: 21 additions & 0 deletions messages/defaultSelectError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @file Default Error Message On Error Select Menu Interaction
* @author Naman Vrati
* @since 3.0.0
*/

module.exports = {
/**
* @description Executes when the select menu interaction could not be fetched.
* @author Naman Vrati
* @param {Object} interaction The Interaction Object of the command.
*/

async execute(interaction) {
await interaction.reply({
content: "There was an issue while fetching this select menu option!",
ephemeral: true,
});
return;
},
};

0 comments on commit 08e53ac

Please sign in to comment.