guidebot Documentation

repository·master·Indexed 19 days ago

https://github.com/anidiotsguide/guidebot

A function-based Discord.js bot boilerplate version 2.1.0 designed to teach developers command and event handling. It includes a command handler, event handler, permission system, per-server configuration, and a logging system. The project provides a template for building Discord bots with built-in system commands such as deploy, eval, reload, and stats.

Tokens
3.5K
Snippets
15
Records
24
Agent score
67%

What's inside guidebot

  1. Overview of Guide Bot features

    master

    Guidebot is a function-based boilerplate for a Discord.js Bot Handler designed to demonstrate command and event handling. It serves as a template for building Discord bots and includes the following core features:

    • Command handler: Manages incoming user commands.
    • Event handler: Manages Discord events.
    • Permission system: A basic system for controlling access to commands.
    • Per-server configuration: Allows for settings to be customized per guild.
    • Logging system: Provides built-in logging capabilities.
    • Basic commands: Includes a set of useful pre-made commands.
  2. Configure Guide Bot requirements and intents

    master

    System Requirements

    • git command line
    • node Version 16.x
    • node-gyp build tools (required for the Enmap module)
    • A Discord Bot Token (obtained from the Discord Developer Portal)

    Discord Intents Configuration

    Guide Bot requires specific Gateway Intents to function. These are loaded from index.js and configured in config.js.

    Required Intents (Default):

    • Guilds
    • GuildMessages
    • DirectMessages

    Privileged Intents:

    • GuildMembers: Required if you want join messages to work. Without this, user counts in the ready log and the stats command may be inaccurate.

    Ensure you enable these intents in your bot's application page under Privileged Gateway Intents in the Discord Developer Portal.

  3. Install and set up Guide Bot

    master

    Follow these steps to clone, install, and configure Guide Bot in a new directory:

    1. Clone the repository:
      git clone https://github.com/anidiotsguide/guidebot.git .
    2. Install dependencies:
      npm install
      Note: If you encounter errors regarding python, msibuild.exe, or binding, ensure you have installed the node-gyp build tools as required by the Enmap module.
    3. Configure the application:
      • Rename config.js.example to config.js. Edit this file to set your required intents and partials.
      • Rename .env-example to .env. Add your Discord bot token to this file.
    4. Start the bot:
      node index.js
    git clone https://github.com/anidiotsguide/guidebot.git .
    npm install
    node index.js
  4. Access the command container via client.container

    master

    To access commands, aliases, or slash commands within the bot (e.g., inside an event handler), use the client.container property. This property acts as a central registry for all loaded bot logic.

    Available properties on client.container:

    • commands: Collection of standard command modules.
    • aliases: Collection mapping alias strings to the primary command name.
    • slashcmds: Collection of slash command modules.
    • levelCache: Object mapping permission level names to their integer levels.
  5. Initialize and run the Guide Bot

    master

    The Guide Bot is initialized by running index.js. The entrypoint performs several setup steps:

    1. Environment Check: Verifies that the system is running Node 16.x or higher. If not, it throws an error.
    2. Configuration: Loads environment variables via dotenv and imports configuration settings (intents, partials, permLevels) from ./config.js.
    3. Client Setup: Initializes a discord.js Client and attaches a container object to it to prevent client pollution. The container holds the following collections:
      • commands: A collection of standard command objects.
      • aliases: A collection mapping aliases to their primary command names.
      • slashcmds: A collection of slash command objects.
      • levelCache: A mapping of permission level names to their numeric levels.
    4. Command Loading: Automatically scans the ./commands/ directory for .js files, registers them in client.container.commands, and populates client.container.aliases based on the command's conf.aliases property.
    5. Slash Command Loading: Scans the ./slash directory for .js files and registers them in client.container.slashcmds using the name defined in command.commandData.name.
    6. Event Loading: Scans the ./events/ directory for .js files and registers them as listeners on the client using client.on(eventName, event.bind(null, client)).
    7. Thread Support: Automatically joins any newly created threads via a built-in threadCreate listener.
    8. Login: Executes client.login() to connect to Discord.
    # Ensure Node version is 16+
    node index.js
  6. Reference: `set` command configuration and help

    master

    The following metadata defines the command's identity, permissions, and usage within the Guide Bot system.

    exports.conf = {
      enabled: true,
      guildOnly: true,
      aliases: ["setting", "settings", "conf"],
      permLevel: "Administrator"
    };
    
    exports.help = {
      name: "set",
      category: "System",
      description: "View or change settings for your server.",
      usage: "set <view/get/edit> <key> <value>"
    };
  7. Configure the eval command settings

    master

    The eval command has the following configuration properties:

    • enabled: true
    • guildOnly: false (can be used in DMs)
    • aliases: []
    • permLevel: Bot Owner (requires highest permission level)

    Command Metadata:

    • Name: eval
    • Category: System
    • Description: Evaluates arbitrary javascript.