Arguments in command
Closed this issue · 1 comments
Cake12356 commented
I was working on a twitch bot, and it would be nice if I could add arguments to the command. How would I do this?
kritzware commented
Hi @Cake12356! There is no built-in support for command arguments at the moment, but a little hacky way you could do it is like this:
Bot.on("message", chatter => {
const splitMsg = chatter.message.split(" ");
const command = splitMsg[0];
if (command === "!cmd") {
const args = splitMsg.slice(1);
console.log({ command, splitMsg, args });
/* Output when typing "!cmd arg1 arg2 arg3" in chat
{
command: '!cmd',
splitMsg: [ '!cmd', 'arg1', 'arg2', 'arg3' ],
args: [ 'arg1', 'arg2', 'arg3' ]
}
*/
}
});
I just wrote this in a couple of minutes, so I'm sure it could be done a better way, and make sure you add some error handling in cases where splitMsg
only contains one item (no arguments).
Hope this helps,