-
Notifications
You must be signed in to change notification settings - Fork 2
How to Create a New Command
Evan Ugarte edited this page Dec 22, 2023
·
4 revisions
- This project is cloned and set up on your computer (see the "How to use" section in the readme
- You have an API key for the discord bot (ask dev lead or Evan for this)
- You are a member of the "SCE-dev" Discord server (ask dev lead or Evan for this)
All of the commands for the discord bot live inside of the src/commands/
folder, which looks like this:
Let's create a new command inside of util/
called square
. Create the file src/commands/square.js
const Command = require('../Command');
module.exports = new Command({
name: 'square',
description: 'Check if the bot is up',
aliases: [],
example: 's!square',
permissions: 'general',
category: 'information',
// eslint-disable-next-line
execute: async (message, args) => {},
});
Looking at the above file, let's go step by step:
-
Command
is a helper class used to organize each command under a name and other information - each
Command
has anexecute
function, which is automatically called when someone runs a command (i.e.s!square
) - the prefix of the command, most commonly
s!
is defined in config.json, specifically in config.example.json:4- you can change it to be whatever you want, for example
x!
and you would run the bot with<prefix><command>
, i.e.x!square
- you can change it to be whatever you want, for example
lets fill out the execute
function with some code to square a value from the user:
it works!
can you try adding the below functionality:
- ensuring a user sent a value to square
- ensuring the value sent is a number