2.3.8 • Published 5 months ago

commands-easy-discord v2.3.8

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Commands Easy Discord

A simple command handler for Discord.js bots.

šŸ“¦ Installation

To install the package, run the following command in the terminal:

npm install commands-easy-discord

šŸš€ Usage

1ļøāƒ£ Project Structure

Your project structure might look like this:

/my-bot
 ā”œā”€ā”€ /commands
 │   ā”œā”€ā”€ ping.js
 ā”œā”€ā”€ bot.js

2ļøāƒ£ Create Commands

Create a file in the /commands folder, for example ping.js:

commands/ping.js

module.exports = {
    name: 'ping',
    description: 'Replies with Pong!',
    execute(message, args) {
        message.reply('šŸ“ Pong!');
    }
};

In this file, you're defining the ping command. When someone types !ping in the chat, the bot will respond with "šŸ“ Pong!".

3ļøāƒ£ Set up the Bot Code

Create a bot.js file (or name it whatever you like) in your main project folder and import commands-easy-discord:

bot.js

const { Client, GatewayIntentBits } = require('discord.js');
const { loadCommands } = require('commands-easy-discord');
require('dotenv').config();

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent
    ]
});

// Load commands from the 'commands' folder
const commands = loadCommands('./commands');

client.on('messageCreate', async (message) => {
    if (!message.content.startsWith("!") || message.author.bot) return;

    const args = message.content.slice(1).trim().split(/ +/);
    const commandName = args.shift().toLowerCase();

    const command = commands.get(commandName);
    if (command) {
        command.execute(message, args);  // Execute the command
    }
});

client.login(process.env.TOKEN);  // Your bot token

4ļøāƒ£ Start the Bot

Once you've set up the code, you can start the bot by running the following command in the terminal:

node bot.js

Now, your bot will respond to commands like !ping and reply with "šŸ“ Pong!".

🌟 Features

āœ… Automatic Command Loading – All commands in the specified folder are automatically loaded.
āœ… Prefix Commands Support – Commands are triggered using a prefix (e.g., !).
āœ… Easy to configure – The command handler is simple to integrate and use.
āœ… Clean Code Structure – Each command is placed in its own file in the commands folder.

šŸ“‚ Directory Structure

  • /commands – This folder contains all your command files.
  • bot.js – This file contains the Discord bot setup and command handler.

Troubleshooting:

  • Command not found: Ensure that the name property in your command file is correctly set (e.g., name: 'ping').
  • Bot is not responding: Make sure the bot is logged in with a valid token, and that the commands folder exists and contains correctly named files.

šŸ“ License

This package is licensed under the MIT License.

---
2.3.8

5 months ago

2.3.7

5 months ago

1.2.0

5 months ago