A 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 types of commands.
A 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 types of commands: Prefix, Slash, User context, and Message context. It can also handle components, including Buttons, Modals, Select menus (any type), and autocomplete.
Did you like my project? Click on the star button (⭐️) right above your screen, thank you!
This Discord bot template uses CommonJS modules. You cannot use import
, export
, or any related keywords from the ES6 modules.
module.exports = {
structure: {
name: string,
description: string,
aliases: string[],
permissions?: PermissionResolvable,
cooldown?: number,
globalCooldown?: boolean,
ownerOnly?: boolean,
developers?: boolean,
nsfw?: boolean
},
run: (client, message, args) => void
};
module.exports = {
structure: SlashCommandBuilder | ContextMenuCommandBuilder,
options?: {
cooldown?: number,
globalCooldown?: boolean,
ownerOnly?: boolean,
developers?: boolean,
nsfw?: boolean
},
run: (client, interaction) => void
};
The ...args
is a spread operator of arguments from the event chosen. For an example, if the event is 'messageCreate', the first argument is going to be type of Message.
module.exports = {
event: string,
once?: boolean,
run: (client, ...args) => void
};
The interaction
is the interaction of the component. For an example, if the custom ID is from a button, the interaction is type of ButtonInteraction.
module.exports = {
customId: string,
options?: {
public?: boolean
},
run: (client, interaction) => void
};
[!WARNING] Installing any version from the package
chalk
that is over v2.4.2 will throw an error that you must enable ES6 modules, while this handler uses CommonJS modules.
src/
and rename example.config.js
to config.js
and fill all the required values. You can use ENV instead of config.js
to keep your bot token and ID, and your MongoDB URI in a secured place by renaming the file .env.example
to .env
and filling all required values.[!CAUTION] Sharing your Discord bot's token with anyone is a very risky move since you'll allow them to use your bot. This is also a dangerous move for the MongoDB database; we don't recommend using any public URIs or sharing your database connection URL.
npm init -y
npm install [email protected] discord.js@latest dotenv mongoose
node .
or npm run start
.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.globalCooldown
(boolean): Determines whether the cooldown is global or not.developers
(boolean): Determines whether the command is executable only to the developers of the bot.nsfw
(boolean): Determines whether this command is executable only in NSFW channels.The component options, each property is optional which means it's allowed to provide an undefined
value to one of these properties below.
public
(boolean): If set to true, the component will be available to everyone (default), if set to false, the component will be available to the component owner (original interaction user) only.This is a common problem for developers, to fix this issue, restart the Discord app or go in a different text channel.
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.
Thank you to all the people who contributed to DiscordJS-V14-Bot-Template!
Join our Discord server if you need any help!
GPL-3.0, General Public License v3