Skip to content

Instantly share code, notes, and snippets.

@trezy
Created March 6, 2022 05:19
Show Gist options
  • Save trezy/492c62f1eca067b344d7cd53ef48d3f0 to your computer and use it in GitHub Desktop.
Save trezy/492c62f1eca067b344d7cd53ef48d3f0 to your computer and use it in GitHub Desktop.
// Local imports
import { capitalise } from '../helpers/capitalise.js'
export class Command {
/****************************************************************************\
* Public methods
\****************************************************************************/
#build() {
this.command = new SlashCommandBuilder()
this.command.setName(this.name)
this.command.setDescription(this.description)
if (this.options) {
this.options.forEach(optionConfig => {
const optionHandler = `add${capitalise(optionConfig.type)}Option`
this.command[optionHandler](option => {
option.setName(optionConfig.name)
option.setDescription(optionConfig.description)
if (optionConfig.choices) {
choices.forEach(choice => {
option.addChoice(...choice)
})
}
if (optionConfig.isRequired) {
option.setRequired(true)
}
return option
})
})
}
}
/****************************************************************************\
* Getters
\****************************************************************************/
get options() {
return this.config.options
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment