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
1
const setStatus = (client, status) => {
2
client.user.setPresence({
3
status: 'online',
4
activity: {
5
name: status
6
}
7
})
8
}
9
10
module.exports = {
11
// Best practice for the built-in help menu
12
category: 'Configuration',
13
description: 'Updates the status for the bot',
14
15
// We need at least 1 word for the status.
16
// maxArgs is -1 by default which means no limit.
17
minArgs: 1,
18
expectedArgs: '<status>',
19
20
// Make this command owner only.
21
// We will set the owner ID(s) in the next code snippet.
22
ownerOnly: true,
23
24
// This method is invoked only once whenever the command is registered
25
init: (client) => {
26
// TODO: Load the status from the database
27
const status = 'Testing' // Would come from the database
28
setStatus(client, status)
29
},
30
31
// This method is invoked anytime the command is ran
32
callback: ({ client, text, message }) => {
33
setStatus(client, text)
34
35
// TODO: Store the status (text variable) to a database
36
37
message.reply({
38
content: 'Status set!'
39
})
40
},
41
}
Copied!
status.ts
1
import { Client } from 'discord.js'
2
import { ICommand } from 'wokcommands'
3
4
const setStatus = (client: Client, status: string) => {
5
client.user?.setPresence({
6
status: 'online',
7
activities: [
8
{
9
name: status,
10
},
11
],
12
})
13
}
14
15
export default {
16
// Best practice for the built-in help menu
17
category: 'Configuration',
18
description: 'Updates the status for the bot',
19
20
// We need at least 1 word for the status.
21
// maxArgs is -1 by default which means no limit.
22
minArgs: 1,
23
expectedArgs: '<status>',
24
25
// Make this command owner only.
26
// We will set the owner ID(s) in the next code snippet.
27
ownerOnly: true,
28
29
// This method is invoked only once whenever the command is registered
30
init: (client: Client) => {
31
// TODO: Load the status from the database
32
const status = "Testing" // Would come from the database
33
setStatus(client, status)
34
},
35
36
// This method is invoked anytime the command is ran
37
callback: ({ client, text, message }) => {
38
setStatus(client, text)
39
40
// TODO: Store the status (text variable) to a database
41
42
message.reply({
43
content: 'Status set!'
44
})
45
},
46
} as ICommand
47
Copied!
Whenever we initialize WOKCommands we can pass in any number of IDs for the owner's Discord accounts:
JavaScript
TypeScript
index.js
1
const DiscordJS = require('discord.js')
2
const WOKCommands = require('wokcommands')
3
const path = require('path')
4
5
const { Intents } = DiscordJS
6
7
const client = new DiscordJS.Client({
8
// These intents are recommended for the built in help menu
9
intents: [
10
Intents.FLAGS.GUILDS,
11
Intents.FLAGS.GUILD_MESSAGES,
12
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
13
],
14
})
15
16
client.on('ready', () => {
17
new WOKCommands(client, {
18
// The name of the local folder for your command files
19
commandsDir: path.join(__dirname, 'commands')
20
})
21
// User your own ID
22
// If you only have 1 ID then you can pass in a string instead
23
.setBotOwner(['your account ID', 'another ID', 'another ID'])
24
})
25
26
client.login('YOUR TOKEN HERE')
Copied!
index.ts
1
import DiscordJS, { Intents } from 'discord.js'
2
import WOKCommands from 'wokcommands'
3
import path from 'path'
4
5
const client = new DiscordJS.Client({
6
// These intents are recommended for the built in help menu
7
intents: [
8
Intents.FLAGS.GUILDS,
9
Intents.FLAGS.GUILD_MESSAGES,
10
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
11
],
12
})
13
14
client.on('ready', () => {
15
new WOKCommands(client, {
16
// The name of the local folder for your command files
17
commandsDir: path.join(__dirname, 'commands'),
18
})
19
// User your own ID
20
// If you only have 1 ID then you can pass in a string instead
21
.setBotOwner(['your account ID', 'another ID', 'another ID'])
22
})
23
24
client.login('YOUR TOKEN HERE')
Copied!
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