-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ | Select Menus Handler & Default Message"
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |