Creating commands

To add commands, you will need to use the builders, which are included in the Zyno Bot addons library. To build the command itself, you will need to use the CommandBuilder class. This builder allows you to easily create a command. The builder creates a structure for the command and will make the bot able to communicate that structure to the Discord API to create the command.

An example of a command is:

const addons = require('zyno-bot-addons');

const myAddon = new addons.Addon({ // Create a new addon
    name: 'My new addon', // The name of your addon
    description: 'Creates a ping command', // A small description of what your addon does
    author: 'Luuk', // Your (user)name so the owner of the copy knows who created the addon
    version: '1.0.0', // The version of your addon
    bitfield: [addons.bitfield.COMMANDS] // The permissions your addon needs
});

const commandBuilder = new addons.CommandBuilder() // Creates a new command
.setName('hello') // Sets the name of the command to 'hello'
.setDescription('Greets you back'); // Sets the description of the command

myAddon.once('ready', () => {
    myAddon.createCommand(commandBuilder).then(cmd => {
        // The command was succesfully created
        cmd.on('execute', command => { // When a user executes the command
            command.reply('Hello!').catch(err => { // Replies with the text 'Hello'
                // An error occured while trying to reply to the command
                console.log(`There was an error while replying to the command:`, err);
            });
        });
    }).catch(err => {
        // An error occured while creating the command
        console.log(`There was an error while creating the command:`, err);
    });
});

This is an example of how you can create new command. The command will be created when the addon is enabled by the owner of the bot and the bot has completed the regular start-up configuration.

After you've built the CommandBuilder, you need to add the command to the bot by using the createCommand function of the Addon class. The argument must be the CommandBuilder class. This will return a Promise which will return a CommandHandler once the command was created.

Last updated