-
Notifications
You must be signed in to change notification settings - Fork 77
Commands
All of the bot's commands are found in the botCommands
folder. The code that listens to and runs the various commands can be found in botEngine.js
. The botEngine scans the entire botCommands directory and loads all .js files, so to create a new command all you have to do is either include it in one of the existing files, or create a new file with your command. New commands should be exported for use in our test files. Commands should be added with the registerBotCommand()
function like so:
const { registerBotCommand } = require("../botEngine.js");
const command = {
regex: /regex/,
cb : ({content, author}) => {
// this function should return either a string, a Discord.js message constructor (such as a Rich Embed) or a promise that resolves a string.
// the string that returns is what the bot will say
return "Hi, I'm a bot lol";
}
}
registerBotCommand(command.regex, command.cb);
module.exports = command
The argument that is passed into the command's callback function is an object provided by Discord that exposes data about the message that triggered the command's regex. For example, the content
is simply the full text of the Discord message. author
refers to the user object that represents the author of the message. Additionally, you can get the username of the author with author.username
. Other properties of note include .mentions
, .channel
, and .reactions
. A full list can be found here.
The full documentation for Discord.JS can be found here.
PLEASE NOTE: We are currently using v11 of Discord.JS. Please ensure you are reading the correct documentation.