nocli-handler.js
  • ๐Ÿ”—Links
    • Link to NPM Package
    • Link to Github Package
  • ๐Ÿš€Introduction
    • Welcome
    • Changelog
  • ๐ŸงชGetting Started
    • Setting Up Your Project
  • โ“Guides
    • Instance
      • Providing a MongoDB Connection
      • Things you really need to know
    • Commands
      • Creating a simple "Ping Pong" Command
      • Command Arguments
      • Enabling Slash Commands
      • Deleting a Command
      • Guild and Owner-only Commands
      • Command Aliases
      • Deferring a command reply
      • Running Events inside a Command
      • Command Cooldowns
      • Setting up Autocomplete
      • Required Permissions
  • ๐ŸซClasses
    • NoCliHandler
      • .connectToMongoDB()
    • ChannelCommands
      • .action()
      • .add()
      • .remove()
      • .getAvailableChannels()
    • Command
    • CommandHandler
      • .getValidations()
      • .readFiles()
      • .runCommand()
      • .isCommand()
    • CustomCommands
      • .loadCommands()
      • .create()
      • .delete()
      • .run()
    • DisabledCommands
      • .loadDisabledCommands()
      • .disable()
      • .enable()
      • .isDisabled()
    • PrefixHandler
      • .loadPrefixes()
      • .get()
      • .set()
    • SlashCommands
      • .getCommands()
      • .findCommand()
      • .optionsAreDifferent()
      • .create()
      • .delete()
      • .createOptions()
    • EventHandler
      • .readFiles()
      • .registerEvents()
      • .isEvent()
  • ๐Ÿ› ๏ธUtilities
    • Cooldowns
      • .loadCooldowns()
      • .getKeyFromCooldownUsage()
      • .cancelCooldown()
      • .updateCooldown()
      • .verifyCooldown()
      • .getKey()
      • .canBypass()
      • .start()
      • .canRunAction()
    • handleCommandAutocomplete
    • handleError
    • log
    • getAllFiles
    • importFile
  • ๐Ÿ†ŽDefinitions
    • NoCliCategoryConfiguration
    • NoCliCategoryType
    • ICommand
    • CommandOptions
    • CommandCallbackOptions
    • NoCliCommandCooldown
    • NoCliCommandType
    • cooldownTypesArray
    • NoCliCooldownType
    • NoCliCooldownKeyOptions
    • IEvent
    • EventConfigurationOptions
    • DynamicValidationConfigurationOptions
    • DynamicValidationCheck
    • DynamicValidationCheckFunction
    • NoCliHandlerOptions
    • NoCliCooldownOptions
    • NoCliCooldownConfigOptions
    • MongoDBConnection
    • MongoDBResult
    • DebugOptions
    • ConfigOptions
    • ValidationPluginsOption
    • NoCliEmojiConfigOptions
    • NoCliLanguageType
    • NoCliRuntimeValidationType
    • NoCliSyntaxValidationType
Powered by GitBook
On this page
  • Setting up a guildonly Command
  • Setting up a ownerOnly command
  1. Guides
  2. Commands

Guild and Owner-only Commands

Some commands should only work in guilds while some cannot. Some commands should also only be used by a bot developer.

PreviousDeleting a CommandNextCommand Aliases

Last updated 2 years ago

Setting up a guildonly Command

We will use the ping command as an example. Set guildonly to true if you want the ping command to work only in guilds.

ping.js
const { NoCliCommandType } = require("nocli-handler.js");

/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    guildOnly: true, // <-- Set guildOnly to true
    type: NoCliCommandType.Both,
    description: "Checks client latency",
    callback: ({ client, message, args, text }) => {
        return `๐Ÿ“ Pong! \`${client.ws.ping}ms\``;
    }
}

module.exports = Command;
ping.ts
import { ICommand, NoCliCommandType } from "nocli-handler.js";

export default {
    guildOnly: true, // <-- Set guildOnly to true
    description: "Checks client latency",
    type: NoCliCommandType.Both,
    callback: ({ client, message, args, text }) => {
        return `๐Ÿ“ Pong! \`${client.ws.ping}ms\``;
    }
} as ICommand;

End Result:

In a Server:

In a Direct Message:

Setting up a ownerOnly command

ping.js
/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    ownerOnly: true, // <-- Set ownerOnly to true
    slash: "both",
    description: "Checks client latency",
    callback: ({ client, message, args, text }) => {
        return `๐Ÿ“ Pong! \`${client.ws.ping}ms\``;
    }
}

module.exports = Command;
ping.ts
import { ICommand } from "nocli-handler.js";

export default {
    ownerOnly: true, // <-- Set ownerOnly to true
    description: "Checks client latency",
    slash: "both",
    callback: ({ client, message, args, text }) => {
        return `๐Ÿ“ Pong! \`${client.ws.ping}ms\``;
    }
} as ICommand;

End Result:

For Normal User:

For Bot Owner:

ownerOnly option requires you to insert an array of IDs for botOwners option (which is mentioned on the page).

โ“
Setting Up Your Project