WOKCommands
  • WOKCommands Documentation
  • Useful Links
    • Setup & Options object
    • 🧠 Build a website dashboard, monetize your bot, and get more users
    • 💰 $100 in FREE Hosting Credits
    • 🙋‍♂️ Support Server
    • 📺 YouTube Channel
  • Commands
    • Ping pong command example
    • Command properties
    • Correct argument usage
    • Command initialization method
    • Bot owner only commands
    • Test servers
    • Cooldowns
    • Required permissions
    • Slash commands
    • Inferred slash command arguments
    • Custom slash command arguments
    • Autocomplete
  • Command Validations
    • Validation setup
    • Runtime validations
    • Syntax validations
  • Event Handler
    • Event Handling
    • Dynamic Validations
  • Features
    • Features
  • Built-in commands and features
    • Enabling and disabling commands
    • Configurable required roles
    • Configurable required permissions
    • Per-guild prefixes
    • Customizable channel specific commands
    • Custom commands
Powered by GitBook
On this page

Was this helpful?

  1. Commands

Bot owner only commands

PreviousCommand initialization methodNextTest servers

Last updated 1 year ago

Was this helpful?

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:

status.js
const { CommandType } = require("wokcommands");

const setStatus = (client, status) => {
  client.user?.setPresence({
    status: "online",
    activities: [
      {
        name: status,
        type: ActivityType.Playing,
      },
    ],
  });
};

module.exports = {
  description: "Sets the bot's status",

  type: CommandType.BOTH,

  minArgs: 1,
  expectedArgs: "<status>",

  ownerOnly: true,

  callback: ({ client, text }) => {
    setStatus(client, text);

    return {
      content: `Set status to "${text}"`,
    };
  },
};
status.ts
import { ActivityType, Client } from "discord.js";
import { CommandObject, CommandType, CommandUsage } from "wokcommands";

const 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 WOKCommands 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.

index.js
const path = require("path");
const WOK = require("wokcommands");
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 WOK({
    client,
    commandsDir: path.join(__dirname, "commands"),
    botOwners: ["Your_ID_Here"]
  });
});

client.login(process.env.TOKEN);
index.ts
import { Client, IntentsBitField, Partials } from "discord.js";
import path from "path";
import WOK from "wokcommands";
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 WOK({
    client,
    commandsDir: path.join(__dirname, "commands"),
    botOwners: ["Your_ID_Here"]
  });
});

client.login(process.env.TOKEN);