Giter VIP home page Giter VIP logo

tfagaming / discordjs-v14-bot-template Goto Github PK

View Code? Open in Web Editor NEW
331.0 6.0 147.0 6.14 MB

A Discord bot with commands, components and events handler based on the latest discord.js v14 and fully written in JavaScript.

License: GNU General Public License v3.0

JavaScript 100.00%
bot-template discord-bot discord-js discord-js-v14 discord-v14 discord-bot-template discord-command-handler discordjs discordjs-v14 discord

discordjs-v14-bot-template's Introduction

DiscordJS-V14-Bot-Template v3

A Discord bot commands, components and events handler based on discord.js v14 and fully written in JavaScript.

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

Features

  • Updated to the latest version of discord.js v14.x.
  • Supports all possible type of commands.
    • Message commands.
    • Application commands:
      • Chat Input
      • User context
      • Message context
  • Handles components.
    • Buttons
    • Select menus
    • Modals
    • Autocomplete
  • Easy and simple to use.
  • Advanced command options.
  • Simple Database included (YAML).

Commands, Components, and Events structure:

Message commands:

Partial.
Awaitable means the function might be async.

new MessageCommand({
    command: {
        name: string, // The command name
        description?: string, // The command description (optional)
        aliases?: string[], // The command aliases (optional)
        permissions?: PermissionResolvable[], // The command permissions (optional)
    },
    options?: Partial<{
        cooldown: number, // The command cooldown, in milliseconds
        botOwner: boolean, // Bot owner can only run it? (true = yes, false = no)
        guildOwner: boolean, // Guild owner can only run it? (true = yes, false = no)
        botDevelopers: boolean, // Bot developers can only run it? (true = yes, false = no)
        nsfw: boolean // The command contains NSFW content? (true = yes, false = no)
    }>,
    run: Awaitable<(client: DiscordBot, message: Message, args: string[]) => void> // The main function to execute the command
});

Application commands (Chat input, User context, Message context):

APIApplicationCommand, Partial.
Awaitable means the function might be async.

new ApplicationCommand({
    command: APIApplicationCommand,
    options?: Partial<{
        cooldown: number, // The command cooldown, in milliseconds
        botOwner: boolean, // Bot owner can only run it? (true = yes, false = no)
        guildOwner: boolean, // Guild owner can only run it? (true = yes, false = no)
        botDevelopers: boolean, // Bot developers can only run it? (true = yes, false = no)
    }>,
    run: Awaitable<(client: DiscordBot, interaction: Interaction) => void> // The main function to execute the command
});

Components:

Autocomplete:

Awaitable means the function might be async.

new AutocompleteComponent({
    commandName: string,
    run: Awaitable<(client: DiscordBot, interaction: AutocompleteInteraction) => void> // The main function to execute the command
});

Buttons, Select Menus, and Modals:

Partial.
Awaitable means the function might be async.

new Component({
    customId: string,
    type: 'modal' | 'select' | 'button',
    options?: Partial<{
        public: boolean // Other users can use the main interaction author button/select? (true = yes, false = no)
    }>
    run: Awaitable<(client: DiscordBot, interaction: Interaction) => void> // The main function to execute the command
});

Events:

Awaitable means the function might be async.
K is a type parameter, extends keyof ClientEvents.

new Event({
    event: K,
    once?: boolean, // The event can only happen once? (true = yes, false = no)
    run: Awaitable<(client: DiscordBot, ...args: ClientEvents[K]) => void>
});

Dependencies

  • colors → latest
  • discord.js → 14.13.0 or newer
  • dotenv → latest
  • quick-yaml.db → latest

Note

Node.js v16.11.0 or newer is required to run discord.js.

Setup

  1. Install a code editor (Visual Studio Code for an example).
  2. Download this project as a .zip file: Download
  3. Extract the .zip file into a normal folder.
  4. Open your code editor, click on Open Folder, and select the new created folder.
  5. Rename the following files:
  • src/example.config.jssrc/config.js: Used for handler configuration.
  • .env.example.env: Used for secrets, like the Discord bot token.
  • example.database.ymldatabase.yml: Used as a main file for the database.
  • example.terminal.logterminal.log: Used as a clone of terminal (to save previous terminal messages).
  1. Fill all the required values in config.js and .env.

Caution

Please remember not to share your Discord bot token! This will give access to attackers to do anything they want with your bot, so please keep the token in a safe place, which is the .env file.

  1. Initialize a new project: npm init (To skip every step, do npm init -y).

  2. Install all required dependencies: npm install colors discord.js dotenv quick-yaml.db

  3. Run the command node . or npm run start to start the bot.

  4. Enjoy! The bot should be online.

Contributing

Feel free to fork the repository and submit a new pull request if you wish to contribute to this project.

Before you submit a pull request, ensure you tested it and have no issues. Also, keep the same coding style, which means don't use many unnecessary spaces or tabs.

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

Support

Join our Discord server if you have any questions to ask, or if you have a problem with this project, you can go to the issues section and submit a new issue.

License

GPL-3.0, General Public License v3

discordjs-v14-bot-template's People

Contributors

adamt20054 avatar atreeshine avatar codeblitz97 avatar codixer avatar panintegralus avatar provant15 avatar saunakghosh10 avatar slendertaker avatar tfagaming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

discordjs-v14-bot-template's Issues

I start the bot on repl.it

But only ping and mymodal commands show up nothing else please explain this to me I already brought up this issue.

Cannot find command handler path. (Only happens on VPS)

I cloned your repo on my local machine. Works perfect. Soon as I clone it on my VPS I get a path error:

Error: ENOENT: no such file or directory, scandir './src/commands/'
    at readdirSync (node:fs:1451:3)
    at module.exports (/home/ubuntu/DiscordJS-V14-Bot-Template/src/handlers/commands.js:10:24)
    at module.exports.start (/home/ubuntu/DiscordJS-V14-Bot-Template/src/class/ExtendedClient.js:37:9)
    at Object.<anonymous> (/home/ubuntu/DiscordJS-V14-Bot-Template/src/index.js:6:8)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: './src/commands/'
} Promise {
  <rejected> Error: ENOENT: no such file or directory, scandir './src/commands/'
      at readdirSync (node:fs:1451:3)
      at module.exports (/home/ubuntu/DiscordJS-V14-Bot-Template/src/handlers/commands.js:10:24)
      at module.exports.start (/home/ubuntu/DiscordJS-V14-Bot-Template/src/class/ExtendedClient.js:37:9)
      at Object.<anonymous> (/home/ubuntu/DiscordJS-V14-Bot-Template/src/index.js:6:8)
      at Module._compile (node:internal/modules/cjs/loader:1218:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
      at Module.load (node:internal/modules/cjs/loader:1081:32)
      at Module._load (node:internal/modules/cjs/loader:922:12)
      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
      at node:internal/main/run_main_module:23:47 {
    errno: -2,
    syscall: 'scandir',
    code: 'ENOENT',
    path: './src/commands/'
  }
}

Fix package.json

Hello,
For success install you need to fix little your package.
Here is full working package.json
{ "name": "discordjs-v14-bot-template", "version": "14.0.0", "description": "A Discord Bot template built by T.F.A#7524!", "main": "index.js", "scripts": { "start": "node index.js" }, "keywords": [], "author": "T.F.A#7524", "license": "ISC", "dependencies": { "better-sqlite3": "^8.2.0", "colors": "^1.4.0", "discord-api-types": "^0.36.2", "discord.js": "^14.5.0", "mathjs": "^11.7.0", "moment": "^2.29.4", "mongoose": "^6.4.4", "ms": "^2.1.3", "node-fetch": "^2.6.7", "pretty-ms": "^6.0.1", "quick.db": "^9.0.5", "super-djs": "^1.7.4" } }

Show only text channels when using options for slash commands

I tried using

channelTypes: ["GUILD_TEXT"],

but that didn't work and I would like to know how to make it so the user can only select text channels in this new versio

also is it still something like const thingy = interaction.options.getString('blahblahblah');
(found out it is but with numbers its getInteger)

Node .

when i do node . it says
C:\Users/name\Downloads\DiscordJS-V14-Bot-Template-2.3.0 (2)>node .
node:internal/modules/cjs/loader:452
throw err;
^

Error: Cannot find module 'C:\Users\name\Downloads\DiscordJS-V14-Bot-Template-2.3.0 (2)\index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (node:internal/modules/cjs/loader:444:19)
at Module._findPath (node:internal/modules/cjs/loader:715:18)
at resolveMainPath (node:internal/modules/run_main:26:23)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:24)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
path: 'C:\Users\name\Downloads\DiscordJS-V14-Bot-Template-2.3.0 (2)\package.json',
requestPath: 'C:\name\eriks\Downloads\DiscordJS-V14-Bot-Template-2.3.0 (2)'
~

pleasr fix

bit of a problem [off-topic](sort of)

I'm trying to make it so that when someone joins, it gives them a role but it isnt working
here's the src

const { EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require("discord.js");
const client = require("../../index");
const config = require("../../config.js");

module.exports = {
  name: "WelcomeSystem"
};

client.on('guildMemberAdd', member => {
    console.log('User: ' + member.user.username + ' has joined the server!');
    member.roles.add("1046263875382808629");
});

Problem with permissions

I place in DEFAULT_MEMBERS_PERMISSION the string "Administrator" but allow all users to execute the command.
Any way to solve it?

webstorm64_VQX3bMFynu

Command Cooldown Request

Hey, I tried like 50 things and asked chatgpt for help but I just simply can't get a command cooldown to work.
Is it possible you guys make it so you can just like type "cooldown: 60000" (in milliseconds) in the "structure:" section in slash commands and maybe like for prefix commands too? Or if that already is a thing please let me know because I am unaware of it

Bot crashes upon any and all DMs

events/Guild/messageCreate.js initiates the constant variable 'prefix' before checking to see if the message was sent in a guild text channel. Because there is no guild.id object for direct messages, this crashes the bot.

node . error

I have all the dependencies but i have the following error:

`C:\Users\Rocío\Videos\DiscordJS-V14-Bot-Template-1.6.0\node_modules\bindings\bindings.js:121
        throw e;
        ^

Error: The module '\\?\C:\Users\Rocío\Videos\DiscordJS-V14-Bot-Template-1.6.0\node_modules\better-sqlite3\build\Release\better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 108. This version of Node.js requires
NODE_MODULE_VERSION 102. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1179:18)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at bindings (C:\Users\Rocío\Videos\DiscordJS-V14-Bot-Template-1.6.0\node_modules\bindings\bindings.js:112:48)
    at new Database (C:\Users\Rocío\Videos\DiscordJS-V14-Bot-Template-1.6.0\node_modules\better-sqlite3\lib\database.js:48:64)
    at Database (C:\Users\Rocío\Videos\DiscordJS-V14-Bot-Template-1.6.0\node_modules\better-sqlite3\lib\database.js:11:10)  
    at new SqliteDriver (C:\Users\Rocío\Videos\DiscordJS-V14-Bot-Template-1.6.0\node_modules\quick.db\out\drivers\SqliteDriver.js:8:25)
    at new QuickDB (C:\Users\Rocío\Videos\DiscordJS-V14-Bot-Template-1.6.0\node_modules\quick.db\out\index.js:17:28) {      
  code: 'ERR_DLOPEN_FAILED'
}
`

Error reading client

TypeError: Cannot read properties of undefined (reading 'set')
at /app/handlers/application_commands.js:72:33

How can i add options?

I tried using the old v13 one but that didnt work... heres what i tried doing:

    options: [
    {
      name: "destination",
      description: "channel to send it in",
      type: "CHANNEL",
      channelTypes: ["GUILD_TEXT"],
      required: true,
    },
],

Unable to load application commands

When i run node .
it gives me this error before starting the bot:
[ERROR] Unable to load application commands to Discord API: Cannot read properties of undefined (reading 'guild')

I haven't used 2 diffrent bots for token and id and havn't touched the slash commands, so im a bit lost here.

What code can i send to help solve this?

how to make add slash command options?

i've tried

const { SlashCommandBuilder } = require("discord.js");

module.exports = {
    name: "test",
    description: "test",
    type: 1,
    options: [],
    permissions: {
        DEFAULT_MEMBER_PERMISSIONS: "SendMessages"
    },
    run: async (client, interaction, config, db) => {
        const data = new SlashCommandBuilder()
        .setName('echo')
        .setDescription('Replies with your input!')
        .addStringOption(option =>
            option.setName('input')
                .setDescription('The input to echo back'));
    },
};

but the input option doesnt show up

Create new command

Hi!

I'm trying to create a new simple command for testing.
Here is my code :

const { ChatInputCommandInteraction, SlashCommandBuilder } = require('discord.js');
const ExtendedClient = require('../../../class/ExtendedClient');

// Pour envoyer un e-mail
//const nodemailer = require('nodemailer');


module.exports = {
    structure: new SlashCommandBuilder()
        .setName('Mail')
        .setDescription('Test d\'envoi de mail'),
    /**
     * @param {ExtendedClient} client 
     * @param {ChatInputCommandInteraction} interaction 
     */
    run: async (client, interaction) => {
        await interaction.reply({
            content: 'Mail envoyé',
            ephemeral: true
        });
    }
};

As you can see, It's just a respond to a message. I also downloaded nodemailer using npm.
Here is a part of the error I'm getting :

ExpectedConstraintError > s.string.regex
  Invalid string format

  Expected: expected /^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u.test(expected) to be true

  Received:
  | 'Mail'

Do you know what's the problem?
Sorry if my English isn't perfect. I'm French.

Modal Error.

Eeverything works but when i click submit the modal gives error. Console is clear and everything works. how do i remove the error in modal
image_2022-09-10_144806837

Cannot Run The Bot in Replit

I been receiving the same response I cannot run the bot and for some reason the bot went online while this response:

Screenshot_20220811-101157

The Bot is Running but I keep saying this and a moment later it turned off
Screenshot_20220811-102337

I wants to use this command from v13

I hade a bot on v13 but now im using ur handler template and i want to use this command how can i do it

const { DiscordTogether } = require('discord-together');

module.exports = {
name:'youtubetogether',
aliases: ['youtube'],
description:'Make Youtube Together',
run: async (client, message, args,prefix) => {

if(!message.member.permissions.has("USE_ACTIVITIES")) return message.channel.send(`You Musst Have USE ACTIVITIES permission.`)
    if(message.member.voice.channel) {
        client.discordTogether.createTogetherCode(message.member.voice.channel.id, 'youtube').then(async invite => {
          return message.channel.send(`Click on the link to start! ${invite.code}`);
        });
      } else {
        if (!message.member.voice.channel) {
            return message.reply('**Please Join Vc At First!**')
        }
      }
}

}

and also i wants change

module.exports = {
config: {
name: "",
description: "",
usage: ""
},

to somthing like this

module.exports = {
name:'youtubetogether',
aliases: ['youtube'],
description:'Make Youtube Together',
run: async (client, message, args,prefix) => {

i main without config things if i cudent wcplain im in ur server BXINO#6217

error in package.json

I tried opening a pull request but it wasnt working for me so im opening an issue.

In line 18 in package.json is missing "," at the end. this can be fixed by changing the line text to ""ms": "^2.1.3","

ID SyntaxError

I am not very talented for this but I copied my bot ID from discord and then put it in the config.js file and then this happens:
B23C292B-AC86-4E05-A0BA-03DF65267F52
How can I fix this ?
(I run the program on replit)

subcommands

you could make subcommands, to be able to name the command with a space for example: Server Icon, not Servericon

test.js not working?

A function in the code seems to not work? This is the user command/app called ./commands/message/test (See images)

image
image

MongoDB problem: ReplicaSetNoPrimary

I forked a bot on repl.it and I didn't change anything, but config.js like it was said in guide. I don't understand why there's problem, because I searched it on internet and I've done what others said - I added my IP on whitelist and it's not working. Please, help me.

image

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.