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

dartcommands

v3.7.0

Published

Dart Commands is a simple command handler to easily create discord bots meant to be lightweight.

Downloads

91

Readme

Dart Commands

Dart Commands is a simple command handler to easily create discord bots meant to be lightweight.

Ongoing Development

You can see the bot currently being developed with DartCommands here

Getting started

To get started with DartCommands just install the package globally and run the CLI tool that automatically creates a boiler plate template

npm i -g dartcommands

And then run the CLI tool

dartcommands

Without the CLI tool

First create your index file index.js

const DartCommands = require("dartcommands");
const { Client, Intents } = require("discord.js");

const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});

// Settings with question marks mean they are optional
client.on('ready', () => {
  new DartCommands(client, {
    commandsDir: 'Commands',
    eventsDir?: 'Events',
    botOwners?: ['user id'],
    ignoreBots?: true | false,
    testServers?: ['server id'],
    typescript?: true | false,
    mongo?: {
      uri: 'mongo connection',
      options?: {
        keepAlive?: true | false
      }
    }
  })
})

Custom Messages

You can integrate your own custom messages when an error occurs like too many arguments, not enough arguments, the default prefix message, etc.

Custom messages can be strings or embeds. When using embeds variables are only applicable in the description property.

new DartCommands(client, {
  commandsDir: "Commands",
}).setLanguageSettings({
  minArgs:
    "Supply at least {MIN} arguments. Syntax for this command is {EXPECTED}", // The 'expectedArgs' options is required in your commands to use the {EXPECTED} variable
  maxArgs: new MessageEmbed({
    title: "Too many arguments",
    description: "You can only supply up to {MAX} arguments",
  }),
  noPermission: "You don't have permission to run this command.",
  ownerOnly: `Only the bot owners can run this command`,
  testOnly: `This command can not be run in this server`,
  prefixUpdated: `Updated this guild's prefix to **{PREFIX}**`,
});

Default Embed Color

You can set the embed color of embeds that are returned from internal commands like '!prefix'. Colors must be provided in a hex format using 0x{HEX}

new DartCommands(client, {
  commandsDir: "Commands",
}).defaultColor(0x000000);

Disabling default commands

You can disable commands that come with DartCommands using the 'disabledDefaultCommands' property

new DartCommands(client, {
  commandsDir: "Commands",
  disabledDefaultCommands: ["prefix"],
});

And that's it! You can now start creating commands for your bot

We're going to create a command that sends "Pong!" as a message

With the recent update, slash commands are now supported!

Commands/ping.js

module.exports = {
  name?: 'ping',
  description: 'Returns pong!',
  ownerOnly?: true | false,
  testOnly?: true | false,
  minArgs?: 1,
  maxArgs?: 2,
  slash?: "both", // Can also be set to true to only be a slash command.
  options: [
    {
      name: "arg1",
      description: "1st argument of slash command",
      required: true,
      type: "STRING"
    },
    {
      name: "arg2",
      description: "2nd argument of slash command",
      type: "STRING"
    }
  ],
  expectedArgs?: '<arg1> [arg2]',
  aliases?: ['p'],
  permission?: 'ADMINISTRATOR',
  async run({
    args,
    channel,
    guild,
    instance,
    member,
    message,
    text,
    user,
    client,
    interaction
  }) {
    return "Pong!"
    or
    return channel.send({ content: "pong!" })
    or
    return {
      custom: true,
      content: "Pong!"
    }
    or
    return new MessageEmbed({
      description: "Pong!"
    })
  }
}

With TypeScript

import { ICommand } from "dartcommands";
export default {
  description: "Returns pong!",
  async run() {
    return "Pong!";
  },
} as ICommand;

Making Events

You can implement your own events through custom files, keeping your events organized. Simply create a folder named 'Events' and add the 'eventsDir' to the options in the DartCommands initializer in index.js

Events/message.js

module.exports.run = (client, instance) => {
  client.on("messageCreate", (message) => {
    // do stuff here
  });
};

module.exports.config = {
  name: "message",
};

With TypeScript

import { Client } from "discord.js";
import DartCommands from "dartcommands";

export const run = (client: Client, instance: DartCommands) => {
  client.on("messageCreate", () => {
    // do stuff here
  });
};

export const config = {
  name: "message",
};

Client Command Event

With the latest update to DartCommands, you can now add an event listener from the client inside your events folder. This could be used for commands such as moderation logging.

Example

// Events/commands.js

module.exports.run = (client) => {
  client.on("Dart.LegacyCommand", (Command, message) => {
    console.log(Command.name, message.author.id);
  });
  client.on("Dart.SlashCommand", (Command, interaction) => {
    console.log(Command.name, interaction.member.user.id);
  });
};

module.exports.config = {
  name: "commands",
};

With Typescript

// Events/commands.ts
import { Client, Message, CommandInteraction, CacheType } from "discord.js";
import { Events, ICommand } from "dartcommands";

export const run = (client: Client) => {
  client.on<Events>(
    "Dart.LegacyCommand",
    (Command: ICommand, message: Message<boolean>) => {
      console.log(Command.name, message.author.id);
    }
  );
  client.on<Events>(
    "Dart.SlashCommand",
    (Command: ICommand, interaction: CommandInteraction<CacheType>) => {
      console.log(Command.name, interaction.member.user.id);
    }
  );
};

export const config = {
  name: "commands",
};