Created
March 6, 2022 05:19
-
-
Save trezy/492c62f1eca067b344d7cd53ef48d3f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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