Closed gzcharleszhang closed 3 years ago
What you could do is make an argument for the "add". Depends if you want to make commands like edit and remove
const { Command } = require('discord.js-commando');
module.exports = class MeowCommand extends Command {
constructor(client) {
super(client, {
...
args: [
{
key: 'action',
prompt: 'specify the action you want to peform',
type: 'string',
oneOf: ['add', 'remove'],
},
{
key: 'imageUrl',
prompt: 'specify the emoji you want to add',
type: 'string'
},
],
});
}
run(message, { action }) {
switch (action) {
case 'add':
//code
break;
case 'remove':
//code
break;
}
}
};
Suppose I want to build a command such as
.emoji add <imageUrl>
where.
is the prefix and<imageUrl>
is the only argument. Since default handling doesn't support commands with a space in its name, so I am using regex for command matching. However, the only one I know how to parse the argument is through using a regex capturing group like so:To get the args I can only do
args[1]
which is the capturing group I specified in the regex. Is there a way to use both patterns matching and leverage Commando's built-in argument parsing/validation, so that I can doargs.imageUrl
or enable prompts when an argument isn't specified like in commands with default handling?