Creating a simple "Ping Pong" Command
At this page, you will learn how to create a simple "Ping Pong" command.
Before creating a command, please make sure you have specified a commands directory with the correct syntax as shown in the Setting Up Your Project page.
How to create a "Ping Pong" Command
Firstly, create a file in the commands directory you specified in the index.js file, and name it ping.js.
Secondly, paste this code into your ping.js file.
const { NoCliCommandType } = require("nocli-handler.js");
/**
* @type {import("nocli-handler.js").ICommand}
*/
const Command = {
type: NoCliCommandType.Legacy,
description: "Checks client latency",
callback: ({ client, message, args, text }) => {
return `๐ Pong! \`${client.ws.ping}ms\``
}
}
module.exports = Command;
Once your program starts, try running the ping command:
For the default prefix during the nocli-handler.js initialization, if you have set any, please replace "!" with the default prefix you have set.
Last updated