Skip to content

Instantly share code, notes, and snippets.

@AlexzanderFlores
Created September 10, 2022 16:53
Show Gist options
  • Save AlexzanderFlores/b60815cd8a586f166bb431239edc1161 to your computer and use it in GitHub Desktop.
Save AlexzanderFlores/b60815cd8a586f166bb431239edc1161 to your computer and use it in GitHub Desktop.
Example of dynamic validations
// This is written in JS but the handler will still have TS support as expected
// CREATE YOUR OWN DYNAMIC VALIDATIONS:
// index.js
new WOKCommands({
client,
commandsDir: path.join(__dirname, 'commands'),
events: {
dir: path.join(__dirname, 'events'),
// First specify the event
interactionCreate: {
// Then specify a dynamic validation function that returns a boolean
// This can be called anything you want
buttons: (interaction) => interaction.isButton()
},
// First specify the event
messageCreate: {
// Then specify a dynamic validation function that returns a boolean
// This can be called anything you want
isHuman: (message) => !message.author.bot
}
},
})
// EXMAPLE FILE PATH: (IMPORTANT)
// ./events/interactionCreate/buttons/event-example.js
// The "buttons" folder is the direct parent of the JS file. So it will look for dynamic validation functions called "buttons" and will only run this function if that dynamic validation returned true.
module.exports = async (interaction, instance) => {
// The interaction is guaranteed to be a button interaction
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment