First of all, what is a Script?

The idea behind a script is to be able to rapidly update and hot-swap features from an application. This is achieved by having the feature scripts listening to events from the persistent server, meaning the individual scripts can be updated without losing state.

How does Canal help?

Canal is specifically for managing discord bots. Back in ye olde days, scripts were managed via Discord chat, but this imposed editor and size limitations. Canal is a solution for this, by being a central source of truth for multiple bots and providing tools dedicated to developing feature scripts.

Environment

Scripts are run in a sandbox which exposes a subset of the variables defined in Node.

At this time, require is not exposed to scripts.

There are three main operations a script can perform:

Running code

The code in a script will be run every time the client loads the script. No extra calls are needed, this is just the body of your script.

Listening to Discord events

The Nodejs client is powered by Discord.js which exposes easy ways to listen to client events. Simply call client.on('event', handler) to register a handler.

The client will do some work in the background to ensure that your handler is terminated with the script.

Registering commands

Calling command('name', handler) will register a command, using the client's built in command logic, provided to simplify adding features.

handler should accept a message, which will have some parsed arguments attatched to it.