Git Product home page Git Product logo

discord_resource's Introduction

DiscordJS-V14-Bot-Template v2

The simplified and popular Discord bot commands & events handler built with discord.js version 14 and written in JavaScript. This handler can load up to 4 different type of commands; Prefix, Slash, User context and Message context. It can also handles components; Buttons, Modal submits, Select menus (any type).

Did you like my project? Click on the star button (⭐️) right above your screen, thank you!

Looking for the old version? Click here.

Features

  • Supports all possible type of commands.
    • Message commands (AKA: Prefix commands).
    • Application commands:
      • Chat Input
      • User context
      • Message context
  • Components Handler.
    • Buttons
    • Select menus
    • Modals
  • Easy and simple to use.
  • Advanced command options (click here).
  • Updated to latest discord.js version.
  • Included a database: MongoDB.

Commands, events, and components structure

Note This handler uses CommonJS modules system.

Prefix:

module.exports = {
    structure: {
        name: string,
        description: string,
        aliases: string[],
        permissions?: PermissionFlagsBits | string,
        cooldown?: number,
        developers?: boolean,
        nsfw?: boolean
    },
    run: async (client, message, args) => Promise<void>
};

Slash/User/Message:

module.exports = {
    structure: SlashCommandBuilder | ContextMenuCommandBuilder,
    options?: {
        cooldown?: number,
        developers?: boolean,
        nsfw?: boolean
    },
    run: async (client, interaction) => Promise<void>
};

Event:

module.exports = {
    event: string,
    once?: boolean,
    // '...args' are the arguments of the event chosen (from discord.js).
    run: async (client, ...args) => Promise<void>
};

Component:

module.exports = {
    customId: string,
    // 'interaction' is the interaction of the component. If the custom ID is from a button, the interaction is type of ButtonInteraction.
    run: async (client, interaction) => Promise<void>
};

Requirements

Packages:

  • chalk v2.4.2
  • discord.js v^14.13.0
  • dotenv v^latest
  • mongoose v^latest

Warning Installing any version from the package chalk that is over v2.4.2, it will throw an error that you must enable ES6 modules, while this handler uses CommonJS modules.

Platforms:

  • Node.js v16.9.0 or newer

Setup

  1. Install Visual Studio Code.
  2. Download this project as a .zip file: Click here
  3. Extract the .zip file into a normal folder.
  4. Open VSCode, click on Open Folder, and select the new created folder.
  5. Go to src/ and rename example.config.js to config.js and fill all the required values.
module.exports = {
    client: {
        token: string, // ← Your bot token (USE .env IS RECOMMENDED)
        id: string // ← Your bot ID (USE .env IS RECOMMENDED)
    },
    handler: {
        prefix: string, // ← The bot prefix
        deploy: boolean, // ← Always load application commands to Discord? (true: Yes, false: No)
        commands: {
            prefix: boolean, // ← Toggle prefix commands
            slash: boolean, // ← Toggle slash commands
            user: boolean, // ← Toggle user commands
            message: boolean // ← Toggle message commands
        },
        mongodb: {
            uri: string, // ← Your MongoDB URI string (USE .env IS RECOMMENDED)
            toggle: boolean // ← Connect to the database or not? (true: Yes, false: No)
        }
    }
}

You can use ENV instead of config.js to keep your bot token and ID and your MongoDB URI in a safe place. Rename the file .env.example to .env and fill all the required values.

CLIENT_TOKEN = Your bot token
CLIENT_ID = Your bot ID
MONGODB_URI = Your mongodb URI string
  1. Initialize a new package and install all required packages:
npm init -y
npm install [email protected] discord.js dotenv mongoose
  1. To start your bot, run node . or npm run start.
  2. Enjoy. =)

Hosting ()

Use Discloud! A trust-worthy Discord bot hosting service.

  1. Login using your Discord/GitHub account, and then don't close the Dashboard tab (because we need it later).
  2. Go to your project on VSCode, create a new file discloud.config. This file is a configuration file for Discloud apps servers. The discloud.config file content must be like the codeblock below, and remember to change YOUR_BOT_ID to your actual bot ID.
ID = YOUR_BOT_ID
TYPE = bot
MAIN = src/index.js
RAM = 100
AUTORESTART = true
VERSION = latest
API = tools
  1. Open explorer and navigate using the path of your project. Hold the CTRL key, and click on src/, package.json, and discloud.config. Now release the key, and right click on the selected files/folders and click on Convert into .zip file.
  2. Go back to the Discloud dashboard, click on Add App, and then upload the .zip file in the upload box. Make sure to accept the ToS of the service and then click on Upload.
  3. Wait for at least 20 seconds (depends on your Internet speed), and then your bot should be on.

Warning Discloud has recently made every Free plan servers into 15 days hosting only. Use the command .rw from their bot in the commands channel (on their Discord server) to reset the timer. Join the server: Click here!

Command options

The command options, each property is optional, which means it's allowed to provide an undefined value to one of these properties below.

  • permissions (PermissionFlagsBits | string): The required permissions for the command, available to message commands only.
  • cooldown (number): The cooldown of the command, in milliseconds.
  • developers (boolean): Whenever the command is executable only to the developers of the bot.
  • nsfw (boolean): Whenever this command is executable only in NSFW channels.

Contributors

Thank you to all the people who contributed to DiscordJS-V14-Bot-Template!

Support

Join our Discord server if you need any help!

FAQs

I'm getting this error: "Unable to load application commands to Discord API"

This error only hapens if your bot token and bot ID are not from the same bot. For an example, if you get a bot token from a bot, and a bot ID from another bot, this will throw the error. If you get the token and the ID from the same bot, it will return no errors.

Is MongoDB required?

No, MongoDB is not required. There is an option to disable it in config.js so you will avoid errors from the commands that requires the database, such as ?prefix. If you want to use the database, visit MongoDB website.

License

GPL-3.0, General Public License v3

discord_resource's People

Watchers

Nguyễn Minh Hùng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.