Discord.js Plugin loading Bot Framework
- Fork the repository
- Clone that repository. (
git clone https://github.com/*/DiscordJS-Segregated-Bot-Framework.git
) - Run
npm install
in cloned directory. - Run
npm run start
to start the bot (include TOKEN environment variable!). - Make and commit changes.
- Open pull request.
To create a new plugin, add a new plugin JS file into the plugins/
directory then add said plugin path excluding plugins/ and the .js extension to config.js.
Called upon the plugin being loaded/enabled.
module.exports = {
name: 'Demo',
enable() {
console.log('Enabled plugin.');
}
};
Called upon the plugin being disabled.
module.exports = {
name: 'Demo',
disable() {
console.log('Disabled plugin.');
}
};
The discord.js client is exported by shard.js.
const {client} = require('../shard');
discord.js' client events are automatically called properties of a plugin.
module.exports = {
name: 'Demo',
message(msg) {
msg.reply('Hello!'); // Note this will cause a loop.
}
}
You may also register events through the client, although this should be avoided. If this is done, ensure you unregister on disable.
module.exports = {
commands: {
label: {
aliases: ['alias'],
exec: (label, args, msg) => {
return 'Response.';
}
}
}
};
An array of alternative labels for a user to execute the command.
The function to be called when a command is called by a user.
Parameter | Description |
---|---|
string label |
The alias used to execute the command. |
array args |
The parameters sent to the command. |
discord.js#Message msg |
The message instance used to execute the command from discord.js. |
HelpCommand.js
uses the following additional properties:
boolean
hidden - If true, the command will not be shown in the help command response.boolean
includeAliasesInHelp - If true, aliases will also be shown in the help menu.string
description - The description of the command.array
parameters - Possible parameters users can give to the command.string
category - The category for the command to be displayed in.
For a full command plugin example see plugins/commands/CoinCommand/
.