DEV Community


Types To Your Discord Bot Command Arguments

shadowtime2000 profile image shadowtime2000 ・1 min read

Install Type Validator

npm install --save discord-arg-validator

Look at structure

How you implement this package really depends on the structure of your bot and what framework you use. Typically, you would want to add the validation to the execute function of your command.

const { validate, String, Number, YesNo } = require("discord-arg-validator");

module.exports = {
    name: 'foo',
    description: 'bar',
    execute(message, args) {
        validate(args, [String, Number, YesNo]).then(() => /* Command logic here */).catch(() =>"Make sure you use the command correctly!")))
Enter fullscreen mode Exit fullscreen mode

You could also use await so you don't have to put your command login in a .then() chain.

Discussion (0)

Editor guide