npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discordbot.json

v1.0.9

Published

Renamed, download from here https://www.npmjs.com/package/easycommands.json

Downloads

1

Readme

Renamed, download from here https://www.npmjs.com/package/easycommands.json

easycommands.json

Description

easycommands.json is an easy way to make discord commands by using a JSON file with input and output key value pairs instead of using a shit ton (Don't deny it) of if statements or switch cases that fill up your code by an unnecessary amount.

Example

Note: init refers to how you defined the easycommands.json module, which is what the example shows.
Note: Can use object instead of JSON File.

Firstly install the package

npm i easycommands.json

Secondly import the easycommands.json module

// ES6 || TypeScript
import init from "easycommands.json";

// CommonJS
const init = require("easycommands.json");

Short Info

There are 2 approaches to the easy commands.

First way being to make a JSON File(s) which will be shown below. - Better because is a file, seperated from code. Easier and more simple to work with as a whole and for beginners. Unless need somewhat complicated commands. JSON is the way to go.

OR

Make an object(s) with the same format as the JSON File. - Better because have better functionatly, can make input be an array from other packages. Use of typescript interface which make it easier to work with.

JSON File

First make the JSON file

{
  "prefix": [{}], // The prefix property is for inputs which need a prefix. OPTIONAL
  "noPrefix": [{}]  // noPrefix property is for responding to plain message content. OPTIONAL
}

Both of noPrefix and prefix have the same properties

JSON File example

{
  "prefix": [{
    "input": "rules", // Input to listen for. REQUIRED (If array, elements acts as aliases)
    "output": "**1.** No being rude.\n**2.** No Ads", // Output to respond. REQUIRED (If array gets random element)
    "messageOptions": { // Discord MessageOptions with custom properties. OPTIONAL
      "split": true,
      "respondToSelf": false, // Custom Property which tells to respond to self or not. DEFUALT: FALSE
      "respondToBots": true, // Custom Property which tells to respond to other bots or not. DEFUALT: TRUE
      "respondToUsers": true, // Custom Property which tells to respond to other users. DEFUALT: TRUE
      "equalContent": false, // Custom Proerty which says to exacly equal input, or just include input. DEFAULT: TRUE
      "embed": { "title": "Check Rules Above!" } // Embed Object https://discordjs.guide/popular-topics/embeds.html#using-an-embed-object
    },
  }],
  "noPrefix": [{
    "input": ["Hello!", "Hey!", "Sup", "Nice to meet you"], //  Input to listen for. REQUIRED  (If array, elements acts as aliases)
    "output": ["Hey!", "GoodBye"], // Output to respond with. REQUIRED (If array gets random element)
    "messageOptions": { // Discord Message Options
    "code": "json"
    },
  }]
}
If copy, Remove code comments from JSON example

Now either call the init function inside or outside the message event.

Example Code Outside Event

const init = require("easycommands.json");
const { Client } = require("discord.js");
const client = new Client();

/* ONLY CALL THE INIT FUNCTION ONCE */

// Outside Event
init(client /* Client Object */, {
  // Options
  commands: "./pathToJSONCommandsFile.json", // Path to JSON file with commands OR JS object of the shown JSON Format. REQUIRED

  logOnReady: true /*  Only for outside event, will log on ready event if true which will log default, or string being own custom message.
  DEFAULT: FALSE */,

  prefix: "!", // Prefix to check for the prefix property inputs. Defualt: "" (Empty String)

  reply: false, // Use message.reply if true for responding to commands. DEFAULT: FALSE
}); // Returns passed Client object
/* Note: init Function Adds commandsJSON property to client, value being the parsed JSON file/Object. */

Example Code Inside Message Event

const init = require("easycommands.json");
const { Client } = require("discord.js");
const client = new Client();

client.on("message", (msg) => {
  const prefix = ExampleDataBase.get(msg.guild.id); // Mocking DB Prefix

  /* ONLY CALL THE INIT FUNCTION ONCE */

  init(client /* Instantiated Client */, {
    // Options

    commands: "./pathToJSONCommandsFile.json", // Path to JSON file. REQUIRED

    prefix: prefix ?? "!", // Prefix to check for the prefix property inputs. Defualt: "" (Empty String)

    reply: false, // Use message.reply if true for responding to commands. DEFAULT: FALSE

    message: msg, // Message object to access the content, etc properties. REQURIED
  }); // Returns Message Object Of Reply || Passed Client
  /* Note: init Function Adds commandsJSON property to client, value being the parsed JSON file/Object. */
});

Object

Object example

// JavaScript
const { MessageEmbed } = require("discord.js");

const Commands = { // Follows same format as JSON.
  prefix: [{
    input: "rules", // Input to listen for. REQUIRED (If array, elements acts as aliases)
    output: "**1.** No being rude.\n**2.** No Ads", // Output to respond. REQUIRED (If array gets random element)
    messageOptions: { // Discord MessageOptions with custom properties. OPTIONAL
      split: true,
      respondToSelf: false, // Custom Property which tells to respond to self or not. DEFUALT: FALSE
      respondToBots: true, // Custom Property which tells to respond to other bots or not. DEFUALT: TRUE
      respondToUsers: true, // Custom Property which tells to respond to other users. DEFUALT: TRUE
      equalContent: false, // Custom Proerty which says to exacly equal input, or just include input. DEFAULT: TRUE
      embed: new MessageEmbed().setTitle("Check Rules above") // Messagembed Constructor https://discordjs.guide/popular-topics/embeds.html#using-the-richembedmessageembed-constructor
    },
  }],
  noPrefix: [{
    input: ["Hello!", "Hey!", "Sup", "Nice to meet you"], //  Input to listen for. REQUIRED  (If array, elements acts as aliases)
    output: ["Hey!", "GoodBye"], // Output to respond with. REQUIRED (If array gets random element)
    messageOptions: {
    code: "json"
    },
  }]
}

// TypeScript
import init, { CommandObject } from "easycommands.json";

const Commands: CommandObject /* TS Interface for command */ {
// ...
}

Now either call the init function inside or outside the message event.

Example Code Outside Event

const init = require("easycommands.json");
const { Client, MessageEmbed } = require("discord.js");
const client = new Client();

const Commands = {
  /* Put example object here */
};

// Outside Event
init(client /* Instantiated Client */, {
  // Options
  commands: Commands, // Path to Command Object. REQUIRED

  logOnReady: true /*  Only for outside event, will log on ready event if true which will log default, or string being own custom message.
  DEFAULT: FALSE */,

  prefix: "!", // Prefix to check for the prefix property inputs. Defualt: "" (Empty String)

  reply: false, // Use message.reply if true for responding to commands. DEFAULT: FALSE
}); // Returns passed Client object
/* Note: init Function Adds commandsJSON property to client, value being the parsed JSON file/Object. */

Example Code Inside Message Event

const init = require("easycommands.json");
const { Client, MessageEmbed } = require("discord.js");
const client = new Client();

const Commands = {
  /* Put example object here */
};

client.on("message", (msg) => {
  const prefix = ExampleDataBase.get(msg.guild.id); // Mocking DB Prefix

  /* ONLY CALL THE INIT FUNCTION ONCE */

  init(client /*  Instantiated Client  */, {
    // Options

    commands: Commands, // Path to Command Object. REQUIRED

    prefix: prefix ?? "!", // Prefix to check for the prefix property inputs. Defualt: "" (Empty String)

    reply: false, // Use message.reply if true for responding to commands. DEFAULT: FALSE

    message: msg, // Message object to access the content, etc properties. REQURIED
  }); // Returns Message Object Of Reply || Passed Client
  /* Note: init Function Adds commandsJSON property to client, value being the parsed JSON file/Object. */
});

More info

Commands property of initOptions allow array of files and objects.

  // File Paths to JSON and Objects
  init(client, {
    commands: ["./commands1.json". "./commands2.json", { prefix: []}, { noPrefix: []}]
  });

  // Just File Paths to JSON
  init(client, {
    commands: ["./commands1.json". "./commands2.json"]
  });

  // Just Objects
  init(client, {
    commands: [{ prefix: []}, { noPrefix: []}]
  });