├── config.json ├── utils └── structures │ ├── BaseEvent.js │ ├── BaseCommand.js │ └── AClient.js ├── app.js ├── package.json ├── events ├── Ready.js └── ACommandHandler.js ├── LICENSE ├── commands ├── Mention.js ├── Ping.js └── Repeat.js ├── .gitignore └── README.md /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "TOKEN": "", 3 | "CLIENT_ID": "", 4 | "GUILD_ID": "" 5 | } -------------------------------------------------------------------------------- /utils/structures/BaseEvent.js: -------------------------------------------------------------------------------- 1 | class BaseEvent { 2 | constructor(options) { 3 | /** 4 | * @type {String} 5 | */ 6 | this.name = options.name; 7 | /** 8 | * @type {Boolean} 9 | */ 10 | this.once = options.once; 11 | } 12 | } 13 | 14 | module.exports = BaseEvent; -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const { Intents } = require('discord.js'); 2 | const { TOKEN, CLIENT_ID, GUILD_ID } = require("./config.json"); 3 | const AClient = require('./utils/structures/AClient.js'); 4 | 5 | (async() => { 6 | const client = new AClient(CLIENT_ID, TOKEN, Object.keys(Intents.FLAGS)); 7 | await client.loadEvents('../../events'); 8 | await client.loadCommands('../../commands', GUILD_ID) 9 | await client.connect(); 10 | })(); 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "discord-app-commands-v13", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "polemikal", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@discordjs/builders": "^0.6.0", 13 | "@discordjs/rest": "^0.1.0-canary.0", 14 | "discord-api-types": "^0.22.0", 15 | "discord.js": "^13.1.0", 16 | "fs": "^0.0.1-security", 17 | "path": "^0.12.7" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /utils/structures/BaseCommand.js: -------------------------------------------------------------------------------- 1 | class BaseCommand { 2 | constructor(options) { 3 | /** 4 | * @type {import("@discordjs/builders").SlashCommandBuilder | import("discord.js").ApplicationCommandData} 5 | */ 6 | this.command = options.command; 7 | /** 8 | * @type {Array} 9 | */ 10 | this.aliases = options.aliases; 11 | /** 12 | * @type {Boolean} 13 | */ 14 | this.guildOnly = options.guildOnly; 15 | } 16 | } 17 | 18 | module.exports = BaseCommand; -------------------------------------------------------------------------------- /events/Ready.js: -------------------------------------------------------------------------------- 1 | const BaseEvent = require("../utils/structures/BaseEvent"); 2 | 3 | class Ready extends BaseEvent { 4 | constructor() { 5 | super({ 6 | name: "ready", 7 | once: false 8 | }) 9 | } 10 | /** 11 | * 12 | * @param {import("../utils/structures/AClient.js")} client 13 | */ 14 | async execute(client) { 15 | client.user.setPresence({ 16 | status: "dnd", 17 | activities: [ 18 | { 19 | name: "Application Commands!", 20 | type: "COMPETING" 21 | } 22 | ] 23 | }) 24 | return client.log("Ready event successfully running!"); 25 | } 26 | } 27 | 28 | module.exports = Ready; -------------------------------------------------------------------------------- /events/ACommandHandler.js: -------------------------------------------------------------------------------- 1 | const BaseEvent = require("../utils/structures/BaseEvent"); 2 | 3 | class ACommandHandler extends BaseEvent { 4 | constructor() { 5 | super({ 6 | name: "interactionCreate", 7 | once: false 8 | }) 9 | } 10 | /** 11 | * 12 | * @param {import("../utils/structures/AClient.js")} client 13 | * @param {import("discord.js").Interaction} interaction 14 | */ 15 | async execute(client, interaction) { 16 | if(interaction.type !== "APPLICATION_COMMAND" && !interaction.isCommand()) return; 17 | const command = client.commands.get(interaction.commandName); 18 | if(command.guildOnly == true && !interaction.inGuild()) return; 19 | return command.execute(client, interaction); 20 | } 21 | } 22 | 23 | module.exports = ACommandHandler; 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 polemikal 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 | -------------------------------------------------------------------------------- /commands/Mention.js: -------------------------------------------------------------------------------- 1 | const BaseCommand = require("../utils/structures/BaseCommand"); 2 | 3 | class Mention extends BaseCommand { 4 | /** 5 | * 6 | * @param {import("../utils/structures/AClient.js")} client 7 | */ 8 | constructor() { 9 | super({ 10 | command: { 11 | name: "mention", 12 | type: 2 // Type 2 is MESSAGE COMMAND. 13 | }, 14 | aliases: ["m"], // Application command aliases. 15 | guildOnly: true // Determines whether your command is only guild. 16 | }); 17 | } 18 | /** 19 | * 20 | * @param {import("../utils/structures/AClient.js")} client 21 | */ 22 | async onLoad(client) { 23 | //... 24 | } 25 | /** 26 | * 27 | * @param {import("../utils/structures/AClient.js")} client 28 | * @param {import("discord.js").ContextMenuInteraction} interaction 29 | */ 30 | async execute(client, interaction) { 31 | const target = interaction.member.guild.members.cache.get(interaction.targetId); 32 | return interaction.reply({ content: target.toString(), ephemeral: false, fetchReply: true }).then(m => setTimeout(() => m.delete(), 5000)); 33 | } 34 | } 35 | module.exports = Mention; -------------------------------------------------------------------------------- /commands/Ping.js: -------------------------------------------------------------------------------- 1 | const { SlashCommandBuilder } = require("@discordjs/builders"); 2 | const BaseCommand = require("../utils/structures/BaseCommand"); 3 | 4 | class Ping extends BaseCommand { 5 | /** 6 | * 7 | * @param {import("../utils/structures/AClient.js")} client 8 | */ 9 | constructor() { 10 | super({ 11 | command: new SlashCommandBuilder() 12 | .setName("ping") 13 | .setDescription("Ping command."), // This option is included in type 1. You can configure this option directly with the SlashCommandBuilder feature. 14 | aliases: ["test-ping"], // Application command aliases. 15 | guildOnly: true // Determines whether your command is only guild. 16 | }); 17 | } 18 | /** 19 | * 20 | * @param {import("../utils/structures/AClient.js")} client 21 | */ 22 | async onLoad(client) { 23 | //... 24 | } 25 | /** 26 | * 27 | * @param {import("../utils/structures/AClient.js")} client 28 | * @param {import("discord.js").CommandInteraction} interaction 29 | */ 30 | async execute(client, interaction) { 31 | return interaction.reply({ content: "Pong!", ephemeral: true }); 32 | } 33 | } 34 | module.exports = Ping; -------------------------------------------------------------------------------- /commands/Repeat.js: -------------------------------------------------------------------------------- 1 | const { TextChannel } = require("discord.js"); 2 | const BaseCommand = require("../utils/structures/BaseCommand"); 3 | 4 | class Repeat extends BaseCommand { 5 | /** 6 | * 7 | * @param {import("../utils/structures/AClient.js")} client 8 | */ 9 | constructor() { 10 | super({ 11 | command: { 12 | name: "repeat", // Application command name. 13 | type: 3 // Type 3 is USER COMMAND. 14 | }, 15 | aliases: ["r"], // Application command aliases. 16 | guildOnly: true // Determines whether your command is only guild. 17 | }); 18 | } 19 | /** 20 | * 21 | * @param {import("../utils/structures/AClient.js")} client 22 | */ 23 | async onLoad(client) { 24 | //... 25 | } 26 | /** 27 | * 28 | * @param {import("../utils/structures/AClient.js")} client 29 | * @param {import("discord.js").ContextMenuInteraction} interaction 30 | */ 31 | async execute(client, interaction) { 32 | const targetChannel = interaction.member.guild.channels.cache.get(interaction.channelId); 33 | const targetMessage = await targetChannel.messages.fetch(interaction.targetId); 34 | return interaction.reply({ content: targetMessage.content, ephemeral: false, fetchReply: true }).then(m => setTimeout(() => m.delete(), 5000)); 35 | } 36 | } 37 | module.exports = Repeat; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # discord-app-commands-v13 2 | A great multiple application command handler bot for Discord servers! 3 | 4 | ![chat_input](https://user-images.githubusercontent.com/68484486/131280767-808f2148-1765-43be-a7f3-310473bdd57d.png) 5 | ![user](https://user-images.githubusercontent.com/68484486/131280771-9ec8adc8-e4d5-4d87-a492-02174c4783ed.png) 6 | ![message](https://user-images.githubusercontent.com/68484486/131280774-bd453034-2438-490c-8de2-c86385eae66a.png) 7 | 8 | ## Features 9 | 10 | - Multiple application command handling. 11 | - Slash command handling. 12 | - User command handling. 13 | - Message command handling. 14 | - Ability to create application commands easily. 15 | 16 | ## 📋 Setup and Run 17 | 18 | 1. Enter TOKEN, CLIENT_ID and GUILD_ID in `config.json` file. (GUILD_ID is optional.) 19 | 2. If guild option is set, give a permission to load application commands for Discord bot (Enter YOUR_CLIENT_ID in URL.) `https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=applications.commands`. 20 | 3. Open a new terminal from project folder then install all modules with `npm i`. 21 | 4. Finally run `app.js` file from terminal. (Example run command: `node app.js`.) 22 | 23 | ## ❓ Application Command Types 24 | 25 | | NAME | VALUE | 26 | | ----------------- | ----- | 27 | | CHAT_INPUT | 1 | 28 | | USER | 2 | 29 | | MESSAGE | 3 | 30 | 31 | ## Links 32 | 33 | - [Application Commands Documents](https://discord.com/developers/docs/interactions/application-commands) 34 | - [Builders Documents](https://github.com/discordjs/builders/blob/HEAD/docs/examples/Slash%20Command%20Builders.md) 35 | 36 | ## Contributing 37 | 38 | Contributions, issues and feature requests are very important! Do not forget [issues page](https://github.com/polemikal/discord-app-commands-v13/issues). 39 | 40 | ## Contact 41 | 42 | - **Discord:** [polemikal](https://discord.com/users/593509502087725252) 43 | - **Instagram:** [@polemikal_](https://www.instagram.com/polemikal_/) 44 | - **My Discord server:** [Help Center](https://discord.gg/ExVjphdKgU) 45 | 46 | ## License 47 | 48 | This project is licensed under the **MIT** license. See the file [LICENSE](https://github.com/polemikal/discord-app-commands-v13/blob/main/LICENSE) for more information. 49 | -------------------------------------------------------------------------------- /utils/structures/AClient.js: -------------------------------------------------------------------------------- 1 | const { Client, Collection } = require("discord.js"); 2 | const BaseEvent = require("./BaseEvent.js"); 3 | const BaseCommand = require("./BaseCommand.js"); 4 | const path = require('path'); 5 | const fs = require('fs').promises; 6 | const { SlashCommandBuilder } = require("@discordjs/builders"); 7 | const { REST } = require('@discordjs/rest'); 8 | const { Routes } = require('discord-api-types/v9'); 9 | 10 | class AClient extends Client { 11 | /** 12 | * 13 | * @param {String} user_id 14 | * @param {String} bot_token 15 | * @param {Array} intents 16 | */ 17 | constructor(user_id, bot_token, intents) { 18 | super({ intents, allowedMentions: { parse: ["everyone", "roles", "users"] }}); 19 | this.user_id = user_id; 20 | this.bot_token = bot_token; 21 | this.commands = new Collection(); 22 | this.log = (content) => { 23 | return console.log(`[${bot_token.substring(Math.floor(bot_token.length / 2))}] ${content}`); 24 | } 25 | this.error = (content) => { 26 | return console.error(`[${bot_token.substring(Math.floor(bot_token.length / 2))}] ERR! ${content}`); 27 | } 28 | } 29 | async connect() { 30 | await this.login(this.bot_token) 31 | .then(() => { 32 | this.log("Successfully connected to \'" + this.user.username + "\' Voice client!") 33 | return this; 34 | }) 35 | .catch((err) => { 36 | this.error("Cannot connect to client: " + err.message); 37 | return this.destroy(); 38 | }); 39 | } 40 | /** 41 | * 42 | * @param {String} dir 43 | * @param {String} guild_id 44 | * @returns 45 | */ 46 | async loadCommands(dir = '', guild_id) { 47 | const filePath = path.join(__dirname, dir); 48 | const files = await fs.readdir(filePath); 49 | const rest = new REST({ version: '9' }).setToken(this.bot_token); 50 | const commands = []; 51 | const guild_commands = []; 52 | for (let index = 0; index < files.length; index++) { 53 | const file = files[index]; 54 | const stat = await fs.lstat(path.join(filePath, file)); 55 | if (stat.isDirectory()) this.loadCommands(this, path.join(dir, file)); 56 | if (file.endsWith('.js')) { 57 | const Command = require(path.join(filePath, file)); 58 | if (Command.prototype instanceof BaseCommand) { 59 | const command = new Command(); 60 | this.commands.set(command.command.name, command); 61 | const aliases = []; 62 | if (command.aliases && Array.isArray(command.aliases) && command.aliases.length > 0) { 63 | command.aliases.forEach((alias) => { 64 | const command_alias = command.command instanceof SlashCommandBuilder ? { ...command.command.toJSON() } : { ...command.command }; 65 | command_alias.name = alias; 66 | aliases.push(command_alias); 67 | this.commands.set(alias, command); 68 | }); 69 | } 70 | if(command.guildOnly) guild_commands.push(command.command instanceof SlashCommandBuilder ? command.command.toJSON() : command.command, ...aliases); 71 | else commands.push(command.command instanceof SlashCommandBuilder ? command.command.toJSON() : command.command, ...aliases); 72 | if (command.onLoad || typeof command.onLoad === "function") await command.onLoad(this); 73 | this.log(`✅ Successfully loaded \'${file}\' command file. (Command: ${command.command.name})`); 74 | } 75 | } 76 | } 77 | try { 78 | if (guild_id && guild_id.length) { 79 | await rest.put( 80 | Routes.applicationGuildCommands(this.user_id, guild_id), 81 | { body: guild_commands }, 82 | ); 83 | } 84 | await rest.put( 85 | Routes.applicationCommands(this.user_id), 86 | { body: commands }, 87 | ); 88 | this.log("✅ Successfully registered application commands."); 89 | } catch (err) { 90 | this.error("Cannot load commands: "+err.message); 91 | } 92 | } 93 | /** 94 | * 95 | * @param {String} dir 96 | * @returns 97 | */ 98 | async loadEvents(dir = '') { 99 | const filePath = path.join(__dirname, dir); 100 | const files = await fs.readdir(filePath); 101 | for (let index = 0; index < files.length; index++) { 102 | const file = files[index]; 103 | const stat = await fs.lstat(path.join(filePath, file)); 104 | if (stat.isDirectory()) this.loadEvents(this, path.join(dir, file)); 105 | if (file.endsWith('.js')) { 106 | const Event = require(path.join(filePath, file)); 107 | if (Event.prototype instanceof BaseEvent) { 108 | const event = new Event(); 109 | if (!event.name || !event.name.length) return this.error(`Cannot load \'${file}\' event file: Event name is not set!`); 110 | if (event.once) this.once(event.name, event.execute.bind(event, this)); 111 | else this.on(event.name, event.execute.bind(event, this)); 112 | this.log(`✅ Successfully loaded \'${file}\' event file. (Event: ${event.name})`); 113 | } 114 | } 115 | } 116 | } 117 | } 118 | 119 | module.exports = AClient; 120 | --------------------------------------------------------------------------------