├── .gitignore ├── src ├── config │ └── config.json ├── events │ └── client │ │ ├── ready.js │ │ ├── interactionCreate.js │ │ └── messageCreate.js ├── slashCommands │ └── information │ │ └── ping.js ├── commands │ └── information │ │ └── ping.js ├── console │ └── watermark.js ├── handlers │ ├── event.js │ ├── command.js │ └── slash.js └── index.js ├── package.json └── LICENCE /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /src/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "TOKEN": "TOKEN HERE", 3 | "CLIENTID": "CLIENT ID HERE", 4 | "PREFIX": "PREFIX HERE", 5 | "OWNER": [ 6 | "OWNER ID HERE" 7 | ] 8 | } -------------------------------------------------------------------------------- /src/events/client/ready.js: -------------------------------------------------------------------------------- 1 | const client = require('../../index'); 2 | const colors = require('colors'); 3 | 4 | module.exports = { 5 | name: "ready" 6 | }; 7 | 8 | client.once('ready', async () => { 9 | console.log("----------------------------------------".white); 10 | console.log(`[READY] ${client.user.tag} is up and ready to go.`.bold) 11 | console.log("----------------------------------------".white); 12 | }) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "colors": "^1.4.0", 4 | "common-tags": "^1.8.2", 5 | "discord.js": "^14.6.0" 6 | }, 7 | "name": "discordjs-v14-handler", 8 | "version": "1.0.0", 9 | "main": "src/index.js", 10 | "scripts": { 11 | "start": "node .", 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "type": "commonjs", 15 | "keywords": [], 16 | "author": "FlameFace#0570", 17 | "license": "ISC", 18 | "description": "" 19 | } 20 | -------------------------------------------------------------------------------- /src/slashCommands/information/ping.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, Client, CommandInteraction } = require('discord.js'); 2 | 3 | module.exports = { 4 | name: 'ping', 5 | description: 'Pong', 6 | // ownerOnly: true, -> Optional 7 | /** 8 | * @param {Client} client 9 | * @param {CommandInteraction} interaction 10 | */ 11 | run: async (client, interaction, args) => { 12 | const embed = new EmbedBuilder() 13 | .setDescription(`🏓 ${client.ws.ping}ms!`) 14 | .setColor('Green') 15 | interaction.reply({ 16 | embeds: [embed] 17 | }) 18 | } 19 | } -------------------------------------------------------------------------------- /src/commands/information/ping.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, Client, Message } = require('discord.js'); 2 | 3 | module.exports = { 4 | name: "ping", 5 | aliases: ["p"], 6 | description: "test command", 7 | userPermissions: ['SendMessages'], 8 | botPermissions: ['ViewChannel'], 9 | // ownerOnly: true, -> Optional 10 | /** 11 | * @param {Client} client 12 | * @param {Message} message 13 | */ 14 | run: async (client, message, args) => { 15 | const embed = new EmbedBuilder() 16 | .setDescription(`🏓 ${client.ws.ping}ms!`) 17 | .setColor('Green') 18 | message.reply({ 19 | embeds: [embed] 20 | }) 21 | } 22 | } -------------------------------------------------------------------------------- /src/console/watermark.js: -------------------------------------------------------------------------------- 1 | const { stripIndent } = require("common-tags"); 2 | const colors = require('colors') 3 | 4 | console.log(stripIndent` 5 | -------------------------------------------------------------------------------------- 6 | ███████╗██╗░░░░░░█████╗░███╗░░░███╗███████╗░██████╗░██╗░░░██╗░█████╗░██████╗░██████╗░ 7 | ██╔════╝██║░░░░░██╔══██╗████╗░████║██╔════╝██╔═══██╗██║░░░██║██╔══██╗██╔══██╗██╔══██╗ 8 | █████╗░░██║░░░░░███████║██╔████╔██║█████╗░░██║██╗██║██║░░░██║███████║██████╔╝██║░░██║ 9 | ██╔══╝░░██║░░░░░██╔══██║██║╚██╔╝██║██╔══╝░░╚██████╔╝██║░░░██║██╔══██║██╔══██╗██║░░██║ 10 | ██║░░░░░███████╗██║░░██║██║░╚═╝░██║███████╗░╚═██╔═╝░╚██████╔╝██║░░██║██║░░██║██████╔╝ 11 | ╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝╚══════╝░░░╚═╝░░░░╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░ 12 | -------------------------------------------------------------------------------------- 13 | `.red.bold) -------------------------------------------------------------------------------- /src/handlers/event.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const colors = require('colors'); 3 | 4 | module.exports = (client) => { 5 | console.log("----------------------------------------".yellow); 6 | 7 | fs.readdirSync('./src/events/').forEach(dir => { 8 | const commands = fs.readdirSync(`./src/events/${dir}`).filter(file => file.endsWith('.js')); 9 | for (let file of commands) { 10 | let pull = require(`../events/${dir}/${file}`); 11 | if (pull.name) { 12 | client.events.set(pull.name, pull); 13 | console.log(`[HANDLER - EVENTS] Loaded a file : ${pull.name}`.green) 14 | } else { 15 | console.log("\n" + "----------------------------------------".red) 16 | console.log(`[HANDLER - EVENTS] Couldn't load the file ${file}, missing name or aliases`.red.bold) 17 | console.log("----------------------------------------".red) 18 | continue; 19 | } 20 | } 21 | }) 22 | console.log("----------------------------------------".yellow); 23 | } -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 FlameQuard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/handlers/command.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const colors = require('colors'); 3 | 4 | module.exports = (client) => { 5 | console.log("----------------------------------------".yellow); 6 | 7 | fs.readdirSync('./src/commands/').forEach(dir => { 8 | const commands = fs.readdirSync(`./src/commands/${dir}`).filter(file => file.endsWith('.js')); 9 | for (let file of commands) { 10 | let pull = require(`../commands/${dir}/${file}`); 11 | if (pull.name) { 12 | client.commands.set(pull.name, pull); 13 | console.log(`[HANDLER - COMMAND] Loaded a file : ${pull.name}`.green) 14 | } else { 15 | console.log("\n" + "----------------------------------------".red) 16 | console.log(`[HANDLER - COMMAND] Couldn't load the file ${file}, missing module name value.`.red.bold) 17 | console.log("----------------------------------------".red) 18 | continue; 19 | }; 20 | 21 | if (pull.aliases && Array.isArray(pull.aliases)) { 22 | pull.aliases.forEach(alias => client.aliases.set(alias, pull.name)) 23 | } 24 | } 25 | }) 26 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | require('./console/watermark') 2 | const { Client, Partials, Collection } = require('discord.js'); 3 | const colors = require('colors'); 4 | const config = require('./config/config.json') 5 | 6 | const client = new Client({ 7 | intents: [ 8 | "Guilds", 9 | "GuildMessages", 10 | "GuildPresences", 11 | "GuildMessageReactions", 12 | "DirectMessages", 13 | "MessageContent", 14 | "GuildVoiceStates" 15 | ], 16 | partials: [ 17 | Partials.Channel, 18 | Partials.Message, 19 | Partials.User, 20 | Partials.GuildMember, 21 | Partials.Reaction 22 | ] 23 | }) 24 | 25 | if (!config.TOKEN) { 26 | console.log("[WARN] Token for discord bot is required! put your token in config file".yellow.bold + "\n") 27 | return process.exit(); 28 | }; 29 | 30 | client.commands = new Collection() 31 | client.events = new Collection() 32 | client.slash = new Collection() 33 | client.aliases = new Collection() 34 | client.config = require("./config/config.json") 35 | 36 | module.exports = client; 37 | 38 | ["command", "event", "slash"].forEach(file => { 39 | require(`./handlers/${file}`)(client); 40 | }); 41 | 42 | client.login(config.TOKEN) 43 | .catch((err) => { 44 | console.log("[CRUSH] Something went wrong while connecting to your bot" + "\n"); 45 | console.log("[CRUSH] Error from DiscordAPI :" + err); 46 | process.exit(); 47 | }) 48 | 49 | process.on("unhandledRejection", async (err) => { 50 | console.log(`[ANTI - CRUSH] Unhandled Rejection : ${err}`.red.bold) 51 | }) -------------------------------------------------------------------------------- /src/handlers/slash.js: -------------------------------------------------------------------------------- 1 | const client = require('../index'); 2 | const config = require("../config/config.json"); 3 | const { REST, Routes } = require('discord.js'); 4 | const fs = require('fs') 5 | const colors = require('colors'); 6 | 7 | module.exports = async () => { 8 | console.log("----------------------------------------".yellow); 9 | 10 | const slash = []; 11 | 12 | fs.readdirSync('./src/slashCommands/').forEach(dir => { 13 | const commands = fs.readdirSync(`./src/slashCommands/${dir}`).filter(file => file.endsWith('.js')); 14 | for (let file of commands) { 15 | let pull = require(`../slashCommands/${dir}/${file}`); 16 | 17 | if (pull.name) { 18 | slash.push(pull) 19 | client.slash.set(pull.name, pull); 20 | console.log(`[HANDLER - SLASH] Loaded a file : ${pull.name}`.green); 21 | 22 | } else { 23 | console.log(`[HANDLER - SLASH] Couldn't load the file ${file}, missing module name value.`.red) 24 | continue; 25 | } 26 | } 27 | }); 28 | 29 | if (!config.CLIENTID) { 30 | console.log("[CRUSH] You have to provide your client ID in config file".red + "\n"); 31 | return process.exit() 32 | }; 33 | 34 | const rest = new REST({ version: '10' }).setToken(config.TOKEN); 35 | 36 | await rest.put( 37 | Routes.applicationCommands(config.CLIENTID), 38 | { body: slash } 39 | ).then(() => { 40 | console.log("----------------------------------------".magenta); 41 | console.log(`[HANDLER - SLASH] Slash commands has been registered successfully to all the guilds`.magenta.bold); 42 | console.log("----------------------------------------".magenta); 43 | }) 44 | } 45 | -------------------------------------------------------------------------------- /src/events/client/interactionCreate.js: -------------------------------------------------------------------------------- 1 | const { PermissionsBitField, EmbedBuilder } = require('discord.js'); 2 | const client = require('../../index'); 3 | 4 | module.exports = { 5 | name: "interactionCreate" 6 | }; 7 | 8 | client.on("interactionCreate", async interaction => { 9 | if (!interaction.isChatInputCommand()) return; 10 | if (!interaction.type == 2) return; 11 | 12 | const command = client.slash.get(interaction.commandName); 13 | 14 | if (!command) return; 15 | 16 | try { 17 | if (command.ownerOnly) { 18 | if (!config.OWNER.includes(interaction.member.id)) { 19 | interaction.reply({ 20 | content: `**${interaction.member}** You can't access owner commands`, 21 | ephemeral: true 22 | }) 23 | return false; 24 | } 25 | } 26 | 27 | if (command.userPermissions) { 28 | if (!interaction.member.permissions.has(PermissionsBitField.resolve(command.userPermissions || []))) return interaction.reply({ 29 | content: `${interaction.member} You don't have the required permissions to use this command -> \`${command.userPermissions || []}\``, 30 | ephemeral: true 31 | }) 32 | return false; 33 | } 34 | 35 | if (command.botPermissions) { 36 | if (!interaction.guild.members.cache.get(client.user.id).permissions.has(PermissionsBitField.resolve(command.botPermissions || []))) return interaction.reply({ 37 | content: `${interaction.member} I don't have the required permissions to use this command -> \`${command.botPermissions || []}\``, 38 | ephemeral: true 39 | }) 40 | return false; 41 | } 42 | 43 | await command.run(client, interaction, interaction.options) 44 | } catch (err) { 45 | console.log(err); 46 | } 47 | }) -------------------------------------------------------------------------------- /src/events/client/messageCreate.js: -------------------------------------------------------------------------------- 1 | const { PermissionsBitField, EmbedBuilder } = require('discord.js'); 2 | const client = require('../../index'); 3 | const config = require('../../config/config.json'); 4 | 5 | module.exports = { 6 | name: "messageCreate" 7 | }; 8 | 9 | client.on('messageCreate', async (message) => { 10 | let prefix = config.PREFIX; 11 | if (message.channel.type !== 0) return; 12 | if (message.author.bot) return; 13 | if (!message.content.startsWith(prefix)) return; 14 | if (!message.guild) return; 15 | if (!message.member) message.member = await message.guild.fetchMember(message); 16 | 17 | const args = message.content.slice(prefix.length).trim().split(/ +/g); 18 | const cmd = args.shift().toLowerCase(); 19 | if (cmd.length == 0) return; 20 | 21 | let command = client.commands.get(cmd); 22 | 23 | if (!command) command = client.commands.get(client.aliases.get(cmd)) 24 | 25 | if (command) { 26 | if (command.ownerOnly) { 27 | if (!config.OWNER.includes(message.member.id)) { 28 | message.reply({ 29 | content: `**${message.member}** You can't access owner commands`, 30 | }) 31 | } 32 | } 33 | 34 | if (command.userPermissions) { 35 | if (!message.member.permissions.has(PermissionsBitField.resolve(command.userPermissions || []))) return message.reply({ 36 | content: `${message.member} You don't have the required permissions to use this command -> \`${command.userPermissions || []}\``, 37 | }) 38 | } 39 | 40 | if (command.botPermissions) { 41 | if (!message.channel.permissionsFor(client.user.id).has(PermissionsBitField.resolve(command.botPermissions || []))) return message.reply({ 42 | content: `${message.member} I don't have the required permissions to use this command -> \`${command.botPermissions || []}\`` 43 | }) 44 | } 45 | 46 | try { 47 | command.run(client, message, args); 48 | } catch (err) { 49 | console.log(err); 50 | } 51 | } 52 | }) 53 | --------------------------------------------------------------------------------