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. NYXBCommands comes with this capability.
Here is how your command file should be setup:
Typescript
import { ActivityType, Client } from 'discord.js'
import { CommandObject, CommandType, CommandUsage } from '@nyxb/commands'
function setStatus(client: Client, status: string) {
client.user?.setPresence({
status: 'online',
activities: [
{
name: status,
type: ActivityType.Playing,
},
],
})
}
export default {
description: 'Sets the bot\'s status',
type: CommandType.BOTH,
minArgs: 1,
expectedArgs: '<status>',
ownerOnly: true,
callback: (options: CommandUsage) => {
const { client, text } = options
setStatus(client, text)
return {
content: `Set status to "${text}"`,
}
},
} as CommandObject
Whenever we initialize NYXBCommands we can pass in any number of IDs for the owner's Discord accounts:
The bot owner's ID is automatically added to the bot owner list. If you are the only developer working on your project you do not need to add your ID.
Typescript
import path from 'node:path'
import { Client, IntentsBitField, Partials } from 'discord.js'
import NYXB from '@nyxb/commands'
require('dotenv/config')
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.MessageContent,
],
partials: [Partials.Channel],
})
client.on('ready', () => {
console.log('The bot is ready')
new NYXB({
client,
commandsDir: path.join(__dirname, 'commands'),
botOwners: ['Your_ID_Here']
})
})
client.login(process.env.TOKEN)
CommandsCommand initialization methodSome commands may require you to run code when they are loaded. You can use the init() method within your command to handle this type of functionality:CommandsTest serversYou may want some commands to only be enabled in specific servers/guilds for testing. This will give you a good idea if something is working in a production environment without risking bugs for your other users.
You can easily specify a command as a "test only" command like so: