WOKCommands
Search…
Bot owner only commands
Some commands should only be available to the bot owners. A perfect example of this is a "status" command that updates the status of your bot. WOKCommands comes with this capability.
Here is how your command file should be setup:
JavaScript
TypeScript
status.js
const setStatus = (client, status) => {
client.user.setPresence({
status: 'online',
activity: {
name: status
}
})
}
module.exports = {
// Best practice for the built-in help menu
category: 'Configuration',
description: 'Updates the status for the bot',
// We need at least 1 word for the status.
// maxArgs is -1 by default which means no limit.
minArgs: 1,
expectedArgs: '<status>',
// Make this command owner only.
// We will set the owner ID(s) in the next code snippet.
ownerOnly: true,
// This method is invoked only once whenever the command is registered
init: (client) => {
// TODO: Load the status from the database
const status = 'Testing' // Would come from the database
setStatus(client, status)
},
// This method is invoked anytime the command is ran
callback: ({ client, text, message }) => {
setStatus(client, text)
// TODO: Store the status (text variable) to a database
message.reply({
content: 'Status set!'
})
},
}
status.ts
import { Client } from 'discord.js'
import { ICommand } from 'wokcommands'
const setStatus = (client: Client, status: string) => {
client.user?.setPresence({
status: 'online',
activities: [
{
name: status,
},
],
})
}
export default {
// Best practice for the built-in help menu
category: 'Configuration',
description: 'Updates the status for the bot',
// We need at least 1 word for the status.
// maxArgs is -1 by default which means no limit.
minArgs: 1,
expectedArgs: '<status>',
// Make this command owner only.
// We will set the owner ID(s) in the next code snippet.
ownerOnly: true,
// This method is invoked only once whenever the command is registered
init: (client: Client) => {
// TODO: Load the status from the database
const status = "Testing" // Would come from the database
setStatus(client, status)
},
// This method is invoked anytime the command is ran
callback: ({ client, text, message }) => {
setStatus(client, text)
// TODO: Store the status (text variable) to a database
message.reply({
content: 'Status set!'
})
},
} as ICommand
Whenever we initialize WOKCommands we can pass in any number of IDs for the owner's Discord accounts:
JavaScript
TypeScript
index.js
const DiscordJS = require('discord.js')
const WOKCommands = require('wokcommands')
const path = require('path')
const { Intents } = DiscordJS
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands')
})
// User your own ID
// If you only have 1 ID then you can pass in a string instead
.setBotOwner(['your account ID', 'another ID', 'another ID'])
})
client.login('YOUR TOKEN HERE')
index.ts
import DiscordJS, { Intents } from 'discord.js'
import WOKCommands from 'wokcommands'
import path from 'path'
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
})
// User your own ID
// If you only have 1 ID then you can pass in a string instead
.setBotOwner(['your account ID', 'another ID', 'another ID'])
})
client.login('YOUR TOKEN HERE')
We suggest using hidden: true in your command properties for owner only commands. This way people don't always see your owner only commands in the built-in help menu.
Copy link