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

vnft-commandhandler

v1.2.0

Published

Discord CommandHandler for TypeScript or JavaScript

Downloads

15

Readme

npm Downloads

This is a bare bones version of vnftjs

vnft-commandhandler

Discord CommandHandler for TypeScript or JavaScript

Table of Contents

Class: CommandHandler

the extended discord.js Client

prefix

the prefix for the commands, . is set by default.

loadCommands(path)

loads all exported command instances of the specified path.

loadScripts(path)

loads all exported script instances of the specified path and triggers them after the client has successfully logged in.

Class: Command

name

the main trigger for the command (without prefix)

funct

the function that gets triggered with the call of the command.
parameters: (client: Client, message: Message, args: string)

Client: the discord client ( extended with the commandhandler )
Message: the message that triggered the command
args: the entire string after the commandname (e.g. .help ping → args:"ping")

addAlias(name)

alternative names for the command, which should also trigger it.

Class: Script

funct

the function that gets executed after the client has successfully logged in.
parameters: (bot: Client)

Client: the discord client ( extended with the commandhandler )

interval

time in ms in which the script-function should be repeated
(negative numbers are disabling the repeat, -1 is the default value)

Examples

JavaScipt

Structure for this example

.
├── main.js
├── commands/
│   ├── ping.js
│   ├── neko.js
│   └── setActivity.js
└── scripts/
    ├── startAsDnd.js
    └── tbd

Code

main.js
const { CommandHandler } = require("vnft-commandhandler");
const path = require("path");

const client = new CommandHandler();
client.prefix = "!";

client.loadCommands(path.join(__dirname, "commands"));
client.loadCommands(path.join(__dirname, "scripts"));

client.login("Discord Token");
commands/ping.js
const { Command } = require("vnft-commandhandler");

const pingCommand = new Command();
pingCommand.name = "ping";

pingCommand.funct = (client, message, args) => {
  message.reply("Pong!");
};

module.exports = pingCommand;
commands/neko.js
const { Command } = require("vnft-commandhandler");
const axios = require("axios");

const neko = new Command();
neko.name = "neko";
neko.addAlias("cat");

neko.funct = async (client, message, args) => {
  var meow = await axios.get("http://aws.random.cat/meow");
  message.reply(meow.data.file);
};

module.exports = neko;
commands/activity.js
const { Command } = require("vnft-commandhandler");

const activity = new Command();
activity.name = "setActivity";
activity.addAlias("activity");

activity.funct = async (client, message, args) => {
  await client.user.setActivity(args);
  message.reply(`Status Updated`);
};

module.exports = activity;
scripts/startAsDnd.js
const { Script } = require("vnft-commandhandler");

const status = new Script();

status.funct = client => {
  client.user.setStatus("dnd");
}

module.exports = status;

TypeScript

Structure for this example:

src/
├── main.ts
├── commands/
│   ├── ping.ts
│   ├── neko.ts
│   └── setActivity.ts
└── scripts/
    ├── startAsDnd.ts
    └── tbd

Code

main.ts
import { CommandHandler } from "vnft-commandhandler";
import * as path from "path";

const client = new CommandHandler();
client.prefix = "!";

client.loadCommands(path.join(__dirname, "commands"));
client.loadCommands(path.join(__dirname, "scripts"));

client.login("Discord Token");
commands/ping.ts
import { Command } from "vnft-commandhandler";
import { Client, Message } from "discord.js";

const ping = new Command();
ping.name = "ping";

ping.funct = (bot: Client, message: Message, args: string) => {
  message.reply("Pong");
};

export = ping;
commands/neko.ts
import { Command } from "vnft-commandhandler";
import { Client, Message } from "discord.js";
import axios from "axios";

const neko = new Command();
neko.name = "neko";
neko.addAlias("cat");

neko.funct = async (bot: Client, message: Message, args: string) => {
  let meow = await axios.get("http://aws.random.cat/meow");
  message.reply(meow.data.file);
};

export = neko;
commands/setActivity.ts
import { Command } from "vnft-commandhandler";
import { Client, Message } from "discord.js";

const activity = new Command();
activity.name = "setActivity";
activity.addAlias("activity");

activity.funct = async (bot: Client, message: Message, args: string) => {
  await bot.user.setActivity(args);
  message.reply(`Activity Updated!`);
};

export = activity;
scripts/startAsDnd.ts
import { Script } from "vnft-commandhandler";

const status = new Script();

status.funct = client => {
  client.user.setStatus("dnd");
}

export = status;