├── LICENSE ├── README.MD ├── config.js ├── index.js └── src └── commands └── example.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 uh! 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 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | #Discord.js v13 Slash Bot
2 | #[Discord Server](https://discord.gg/Qdbq2v8FM4) 3 | 4 | ## 🛠 Setup 5 | - Run the `npm install` command on the Powershell. 6 | - Wait until the process is finished. 7 | - Go to [discord.dev](https://discord.dev) page. 8 | - Create a bot. 9 | - Click on `Bot` on the left side. 10 | - Click `Add Bot` on the right. 11 | - Copy the bot's token. 12 | - Fill the all fields in `config.js`. 13 | - Finally run the `node index.js` command on the Powershell. 14 | 15 | ## ✨ For Developers 16 | | Number | Type | 17 | | :---: | :---: | 18 | | 1 | Sub Command | 19 | | 2 | Sub Command Group | 20 | | 3 | String | 21 | | 4 | Integer | 22 | | 5 | Boolean | 23 | | 6 | User | 24 | | 7 | Channel | 25 | | 8 | Role | 26 | | 9 | Mentionable | 27 | | 10 | Number | 28 | | 11 | Attachment | 29 | 30 | 31 | ## ⭐ Star 32 | - Don't forget to star this repo for support :) 33 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | const { Intents } = Discord; 2 | 3 | module.exports = { 4 | client: { 5 | token: "", 6 | status: "Developed with ❤️ by clqu", 7 | intents: [ 8 | Intents.FLAGS.GUILDS 9 | ], 10 | }, 11 | commandsDir: './src/commands', 12 | prefix: '(!): ' 13 | } 14 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js'); 2 | const { Client, Intents } = Discord; 3 | const config = require("./config"); 4 | const { REST } = require("@discordjs/rest"); 5 | const { Routes } = require("discord-api-types/v9"); 6 | const fs = require('fs'); 7 | 8 | // =================================================================================== \\ 9 | const client = new Client({ 10 | intents: config.client.intents, 11 | }); 12 | // =================================================================================== \\ 13 | 14 | let commands = []; 15 | fs.readdir(config.commandsDir, (err, files) => { 16 | if (err) throw err; 17 | files.forEach(async (f) => { 18 | try { 19 | let props = require(`${config.commandsDir}/${f}`); 20 | commands.push({ 21 | name: props.name, 22 | description: props.description, 23 | options: props.options 24 | }); 25 | } catch (err) { 26 | console.log(err); 27 | } 28 | }); 29 | }); 30 | 31 | // =================================================================================== \\ 32 | 33 | const rest = new REST({ version: "9" }).setToken(config.client.token); 34 | client.once("ready", () => { 35 | (async () => { 36 | try { 37 | await rest.put(Routes.applicationCommands(client.user.id), { 38 | body: await commands, 39 | }); 40 | console.log(config.prefix + "Successfully reloaded application [/] commands."); 41 | } catch { }; 42 | })(); 43 | }); 44 | 45 | // =================================================================================== \\ 46 | 47 | client.on("interactionCreate", async (interaction) => { 48 | if (!interaction.isCommand()) return; 49 | // ========[ COMMAND BUILDER ]========== \\ 50 | fs.readdir(config.commandsDir, (err, files) => { 51 | if (err) throw err; 52 | files.forEach(async (f) => { 53 | let props = require(`${config.commandsDir}/${f}`); 54 | if (interaction.commandName.toLowerCase() === props.name.toLowerCase()) { 55 | try { 56 | if ((props?.permissions?.length || [].length) > 0) { 57 | (props?.permissions || [])?.map(perm => { 58 | if (interaction.member.permissions.has(config.permissions[perm])) { 59 | return props.run(client, interaction); 60 | } else { 61 | return interaction.reply({ content: `Missing permission: **${perm}**`, ephemeral: true }); 62 | } 63 | }) 64 | } else { 65 | return props.run(client, interaction); 66 | } 67 | } catch (e) { 68 | return interaction.reply({ content: `Something went wrong...\n\n\`\`\`${e.message}\`\`\``, ephemeral: true }); 69 | } 70 | } 71 | }); 72 | }); 73 | // ========[ COMMAND BUILDER ]========== \\ 74 | }); 75 | 76 | // =================================================================================== \\ 77 | client.once("ready", () => { 78 | // ================ \\ 79 | console.log(config.prefix + "Client successfully connected."); 80 | // ================ \\ 81 | client.user.setStatus('ONLINE'); 82 | client.user.setActivity(config.client.status); 83 | // ================ \\ 84 | }) 85 | 86 | // =================================================================================== \\ 87 | 88 | // =================================================================================== \\ 89 | client.login(config.client.token); 90 | // =================================================================================== \\ 91 | -------------------------------------------------------------------------------- /src/commands/example.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: "example", 3 | description: "Command", 4 | permissions: ["MANAGE_GUILD"], 5 | options: [ 6 | { type: 6, name: 'user', description: 'Mention user.', required: false }, 7 | { type: 7, name: 'channel', description: 'Mention channel.', required: false } 8 | /* 9 | If you search more option types? 10 | Check it; https://github.com/clqu/discord.js-v13-slash-bot#for-developers 11 | */ 12 | ], 13 | run: async (client, interaction) => { 14 | const _user = interaction?.options?.get("user")?.user; 15 | const _channel = interaction?.options?.get("user")?.channel; 16 | /* 17 | interaction.options.get("optionName") 18 | */ 19 | 20 | /* 21 | And I recommend using interaction.reply 22 | Because otherwise you will have to write a text to indicate who the message belongs to, 23 | interaction.reply in slash commands will be best for you. 24 | */ 25 | if (channel) { 26 | await interaction.reply({ content: `${client.user.username} | ${channel.id}`, ephemeral: true }) 27 | } 28 | if (user) { 29 | await interaction.followUp({ content: `${client.user.username} | ${user.username}`, ephemeral: true }) 30 | } 31 | /* 32 | Why using followUp? 33 | > Because we can reply once in slash commands, but if we want 34 | > to write more than one, we can provide multiple replies using followUp. 35 | > But it is not a method that I highly recommend. 36 | */ 37 | }, 38 | }; 39 | --------------------------------------------------------------------------------