yuuko
yuuko copied to clipboard
Options-first Command and EventListener constructors
Fixes #96. Constructors for Command and EventListener currently take an optional object argument for additional options. However, because these both have required function arguments that can have long bodies, it can hurt readability to have options that impact how the function is run at the very bottom of the constructor, especially when working with single-file commands.
This PR adds support for passing the the object argument before the function argument in both these cases, and deprecates the signatures that put the function argument first. Signatures still exist to allow passing no object argument; both these constructors treat that case identically to passing an empty object.
- [x] Command constructor
- [ ] CommandWithHelp constructor
- [ ] EventListener constructor
- [ ] Migrate internal usage in default commands
what the deprecation will say
Deprecation: Object-last Client and EventListener constructor signatures
The `Command` and `EventListener` constructors both take an optional object argument containing additional options. #98 introduced new forms for these constructors, which place the options argument before the function argument, and deprecated the old forms which place the options argument at the end of the argument list.
Deprecated forms can be replaced by simply switching the position of the arguments, like so:
```js
// old
new Command('test', message => {
// ...
}, {
guildOnly: true,
permissions: ['manageMessages'],
})
new EventListener('ready', () => {
// ...
}, {once: true})
// new
new Command('test', {
guildOnly: true,
permissions: ['manageMessages'],
}, message => {
// ...
})
new EventListener('ready', {once: true}, () => {
// ...
})
```
Omitting the object argument entirely is still supported:
```js
new Command('ping', message => {
// ...
})
new EventListener('messageCreate', message => {
// ...
})
```
The object-last constructor signatures of `Command` and `EventListener` will be removed in the 3.0.0 release.
Blocked on #84, I ain't dealing with that EventEmitter constructor until it's reasonable