Corebot has a simple addon system that allows you to easily implement your custom features while not editing Corebot's code. Continue reading to learn how to create an addon!
Note: This guide goes over the basics of setting up an addon, creating a command, and working with events. We recommend that you already have decent knowledge over Javascript and discord.js before attempting to create an addon. We offer very little coding support.
Navigate to the addons folder and create a file with a .js file type. (For example: test-addon.js, custom-ping-command.js, etc.)
Open the newly created addon file and add this code to the file:
const Utils = require('../src/modules/utils')
module.exports = {
run: async bot => {
// Write your addon code here!
},
messages: { // Optional - Messages that will print to console instead of Corebot's default addon loaded/unloaded messages
loaded: "[Test] Loaded addon.",
unloaded: "[Test] Unloaded addon."
},
dependencies: [], // Optional - Array of node module names that the addon requires. Dependencies must be loaded in the run method
configs: { // Optional - If your addon doesn't need a config, you can remove the configs setting/object
config: {
// Your addon's config. Add settings here
}
}
}
Note: Importing the Utils module is not required, although it gives you access to some extremely handy tools to speed up the coding process!
Corebot has an advanced command handler which allows you to easily implement new commands to the bot. To start, you will need to import our command handler by adding the following code:
const CommandHandler = require('../src/modules/handlers/CommandHandler')
Now that the command handler is imported, you can create a command by using this format:
CommandHandler.set({
name: "command name",
run: async (bot, messageOrInteraction, args, { slashCommand, prefixUsed, commandUsed, type, user, member, guild, channel, reply }) => {
// Write your command's code here!
},
description: "Command description here",
usage: "Command usage here",
aliases: [],
type: "[custom] module name",
arguments: []
})
Note: legacy command refers to a command ran using a normal Discord message, instead of Discord's slash commands
name
- The name command.run
- This is the actual command's code. The function has the following arguments passed into it:
message
if the command was ran using legacy commands, or interaction
if the command was ran using slash commandsdescription
- A short description of the command.usage
- The usage of the command. For example, ban <@user> [reason]
aliases
- An array of aliases a user can use to run the command. For example,["ping", "botping", "pong"]
type
- This is the module the command will go under. You can use one of Corebot's pre-existing modules like admin
or giveaways
, or you can create your own module by simply writing the name of the module you would like to create. If the module name doesn't already exist in the database, Corebot will enter it in for you!arguments
- Only required for slash commands. This is an array of your slash command's options/parameters. Refer to https://discord.js.org/#/docs/discord.js/stable/typedef/ApplicationCommandOption for more info on building the option objectOur command handler does not need to be used to create commands, although it is HIGHLY recommended that you use it. You will lose many features if you do not. If you chose not to, the command will not automatically be added to the help menu, command logs will not work for this command, cooldowns will not work for this command, etc.
Corebot also has an easy to use event handler. To begin, you will want to import the event handler by adding the following code:
const EventHandler = require('../src/modules/handlers/EventHandler.js')
Then, you will need to add an event listener by adding the following code:
EventHandler.set('eventName', async (bot, ...eventArguments) => {
// Write the event code here!
})
Note: Do not actually put ...eventArguments
! You need to put the arguments that are passed into the event by discord.js (or either your or our custom events). For example:
EventHandler.set('guildMemberUpdate', async (bot, oldMember, newMember) => {
})
Discord.js allows us to create custom events using their event emitter. It can be done by writing the following code:
bot.emit('customEventName', bot, ...customEventArguments)
Example:
bot.emit('ticketCreated', bot, ticket, channel)