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

Ping pong command example

PreviousSetup & Options objectNextCommand properties

Last updated 1 year ago

Was this helpful?

WOKCommands is easy to get setup and working. On this page you will learn how to create a simple "Ping -> Pong" command.

First you must setup WOKCommands in your main file:

index.js
const { Client, IntentsBitField, Partials } = require("discord.js");
const WOK = require("wokcommands");
const path = require("path");
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", () => {
  new WOK({
    client,
    commandsDir: path.join(__dirname, "commands"),
  });
});

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

client.login(process.env.TOKEN);

Then create a "commands" folder where you can create a "ping.js" file with the following contents:

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

module.exports = {
  // Required for slash commands
  description: "Ping pong command",
  
  // Create a legacy and slash command
  type: CommandType.BOTH,

  // Invoked when a user runs the ping command
  callback: () => {
    // Return the same object you would use in
    // message.reply
    // or
    // interaction.reply
    // WOKCommands will reply to the message or the interaction
    // depending on how the user ran the command (legacy vs slash)
    return {
      content: "Pong!",
    }
  },
}
ping.ts
import { CommandObject, CommandType } from "wokcommands";

export default {
  // Required for slash commands
  description: "Ping pong command",
  
  // Create a legacy and slash command
  type: CommandType.BOTH,

  // Invoked when a user runs the ping command
  callback: () => {
    // Return the same object you would use in
    // message.reply
    // or
    // interaction.reply
    // WOKCommands will reply to the message or the interaction
    // depending on how the user ran the command (legacy vs slash)
    return {
      content: "Pong!",
    }
  },
} as CommandObject

After inviting your bot to a Discord server and running !ping ("!" is the default command prefix) or /ping, your bot should reply with Pong!.