Creating your First Command - TimmyRB/SydneyBot GitHub Wiki
Setup
Create a new file in SydneyBot/src/commands
called myCommand.ts
Add these imports at the top of your file
import { Permissions } from 'discord.js';
import { Command } from '../../lib/models/bot';
The first import brings Discord.js' Permissions object that we will use later for defining who can run this command. The second import imports the Command Model which will let us easily create a command!
Next, we'll define our Command
export const MyCommand = new Command({
name: 'mycommand',
desc: 'Runs my Command!',
usage: '!mycommand',
permissions: new Permissions(),
callback: (msg, args, dbUser) => {
// Your Custom Code Here
}
})
- name - How our command will be run
- desc - Description of our command that will be shown in the Help Menu
- usage - Example usage of the command shown in Help Menu
- permissions - Permissions required to run the Command
- callback - Runs once args are parsed & Database User is fetched
Permissions
No Permissions Required
permissions: new Permissions(),
One Permission Required
permissions: new Permissions('MANAGE_CHANNELS'),
Two Permissions Required
permissions: new Permissions('MANAGE_CHANNELS').add('ADD_REACTIONS'),
You can keep chaining the .add()
function to add as many Permissions as you want.
permissions: new Permissions('MANAGE_CHANNELS').add('ADD_REACTIONS').add('BAN_MEMBERS').add('MANAGE_ROLES'),
Check out the Discord Docs for a full list of possible Permissions that can be added.
Finishing the Command
Let's do something simple like a reply to the user with a cool message.
callback: (msg, args, dbUser) => {
msg.reply('hey there!')
}
Now we need to add our command to the bot so it actually runs!
In Sydneybot/src/index.ts
add this under everything else
export { MyCommand } from './myCommand'
Then, in SydneyBot/bot.ts
, add your Command to the Commands array
const commands: Command[] = [Commands.MyCommand, ...]
That's it! Your Command can now be run and will appear in the Help Menu!