3.7.0 • Published 2 years ago

dartcommands v3.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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",
};
3.6.12

2 years ago

3.7.0

2 years ago

3.5.7

2 years ago

3.3.9

2 years ago

3.5.6

2 years ago

3.3.8

2 years ago

3.5.5

2 years ago

3.3.7

2 years ago

3.5.4

2 years ago

3.3.6

2 years ago

3.5.9

2 years ago

3.5.8

2 years ago

3.4.0

2 years ago

3.6.2

2 years ago

3.4.4

2 years ago

3.6.1

2 years ago

3.4.3

2 years ago

3.6.0

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

3.6.6

2 years ago

3.4.8

2 years ago

3.6.5

2 years ago

3.4.7

2 years ago

3.6.4

2 years ago

3.4.6

2 years ago

3.6.3

2 years ago

3.4.5

2 years ago

3.6.9

2 years ago

3.6.8

2 years ago

3.6.7

2 years ago

3.4.9

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.6.11

2 years ago

3.5.3

2 years ago

3.3.5

2 years ago

3.6.10

2 years ago

3.5.2

2 years ago

3.3.4

2 years ago

3.5.1

2 years ago

3.3.3

2 years ago

3.5.0

2 years ago

3.3.2

2 years ago

3.2.5

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.9

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago