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

Command initialization method

PreviousCorrect argument usageNextBot owner only commands

Last updated 1 year ago

Was this helpful?

Some 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:

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

module.exports = {
  description: "Ping pong command",
  type: CommandType.BOTH,

  init: (client, instance) => {
    console.log("Ping command has been loaded");
  },

  callback: () => {
    return {
      content: "Pong!",
    };
  },
};
ping.ts
import { Client } from "discord.js";
import WOKCommands, { CommandObject, CommandType } from "wokcommands";

export default {
  description: "Ping pong command",
  type: CommandType.BOTH,

  init: (client: Client, instance: WOKCommands) => {
    console.log("Ping command has been loaded");
  },

  callback: () => {
    return {
      content: "Pong!",
    };
  },
} as CommandObject;