├── LICENSE ├── README.md ├── config.json └── index.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Masih 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 | Before you get started anything you need to create your NEW Application bot in [Discord Developer Portal](https://discord.com/developers/applications?new_application=true), Then copy and save your Application Bot's TOKEN (Please don't share this with anyone, Because whoever has it will have full access to your bot, for example they can Nuked your server!) 2 | **Make sure that your Bot have access to the Intents in the Portal.** 3 | 4 | Now you need to install JavaScript Environment Run (Node.js) in your Computer, Simply visit the https://nodejs.org and download the version 16.9 or higher, Because the Discord.js V14 is only valid in this version! 5 | 6 | After the download is complete, Open your code Editor, I recommend for you to use Visual Studio Code, You can download this Application on your computer in https://code.visualstudio.com 7 | 8 | Now Open your Toggle Panel with 9 | ``` 10 | CTRL + J 11 | ``` 12 | Select the Terminal Option and Type 13 | ``` 14 | npm init -y 15 | ``` 16 | for creating a place which name is `package.json` file to save your modules. 17 | 18 |
19 | 20 | Now you need to install all of required packages/libraries such as Discord.js module with these commands below and waiting for each of them: 21 | 22 | ``` 23 | npm install discord.js 24 | ``` 25 | and then 26 | ``` 27 | npm install @discordjs/voice 28 | ``` 29 | 30 |
31 | 32 | After the operation was processed with any error, please create a NEW file with 33 | ``` 34 | CTRL + Alt + Windows + N 35 | ``` 36 | and set the name to anything you want such as: `index.js`, `bot.js`, `main.js` 37 | 38 | Then Upload the source of this repository along with your personal information for example: `botToken`, `prefix`, `voiceChannelId` and `rgbRoleId` in the [config.json](https://github.com/CalledMasih/Creating-Discord-Bot/blob/main/config.json) file. 39 | 40 | Finally enter the following command in your terminal to run/executing your file and wait for response in the console log... 41 | ``` 42 | node fileName.js 43 | ``` 44 | 45 | 🎉 Congratulations, your bot was successfully online for provide lot's of amazing features! 46 | 47 | 48 | 49 | ## Images 50 | Ping & Uptime Command 51 | 52 | ![Ping Command](https://github.com/CalledMasih/Creating-Discord-Bot/assets/100484009/e89b4627-4c00-43af-a0d5-b68ea2aac0f8) 53 | 54 | 55 | Join to a Voice Channel 56 | 57 | ![Join Voice Channel](https://github.com/CalledMasih/Creating-Discord-Bot/assets/100484009/1e96a076-da84-462d-af71-71b02b31fb92) 58 | 59 | 60 | RGB Role (Randomly changes the color of your provided role every **5** minutes) 61 | 62 | ![RGB Role](https://github.com/CalledMasih/Creating-Discord-Bot/assets/100484009/e4fa79c9-2271-4f8a-bd64-c56e98537ac7) 63 | 64 | 65 | - If you have a problem while using this source make sure your to DM me on Discord: [CalledMasih](https://discord.com/users/901765485341859911), I will help you and fix your issue ASAP. 66 | - To get more information of How these codes work? you can simply check official guidelines in: https://discordjs.guide/ website. 67 | > Copyright (c): Masih 2022/12/16, All right reserved! 68 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "botToken": "YOUR BOT TOKEN", 3 | "prefix": "YOUR PREFIX", 4 | "voiceChannelId": "YOUR VOICE CHANNEL ID", 5 | "rgbRoleId": "YOUR RGB ROLE ID" 6 | } 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | Make Online your Bot in Discord.js V14 3 | Hope you Enjoy, Made with 🤍 by CalledMasih 4 | GitHub: https://github.com/calledmasih | Don't forget to ⭐ 5 | Website: https://calledmasih.ir/ 6 | Copyright Masih 2024 All Right Reserved! 7 | */ 8 | 9 | const { 10 | Client, 11 | GatewayIntentBits, 12 | EmbedBuilder, 13 | ActivityType, 14 | } = require("discord.js"); 15 | const { joinVoiceChannel } = require("@discordjs/voice"); 16 | const config = require("./config.json"); 17 | const client = new Client({ 18 | intents: [ 19 | GatewayIntentBits.Guilds, 20 | GatewayIntentBits.GuildMessages, 21 | GatewayIntentBits.GuildMembers, 22 | GatewayIntentBits.MessageContent, 23 | GatewayIntentBits.GuildPresences, 24 | ], 25 | }); 26 | 27 | client.on("ready", async () => { 28 | const voiceChannel = client.channels.cache.get(config.voiceChannelId); 29 | // Make Random status and Activity 30 | async function changeStatus() { 31 | const members = await voiceChannel.guild.members.fetch({ 32 | withPresences: true, 33 | }); 34 | const onlineMembersCount = members.filter( 35 | (m) => 36 | m.presence?.status === "online" || 37 | m.presence?.status === "idle" || 38 | m.presence?.status === "dnd" 39 | ).size; 40 | const activeMicsCount = members.filter((m) => m.voice.channel).size; 41 | const activityName = [ 42 | `${voiceChannel.guild.name}`, // Guild Name 43 | `${voiceChannel.guild.memberCount} Members`, // Guild Members Count 44 | `${onlineMembersCount} Online`, // Online Guild Members Count 45 | `${activeMicsCount} Active Mics`, // Total Members that Join to a Voice Channel 46 | ]; 47 | const activityType = [ 48 | ActivityType.Competing, 49 | ActivityType.Watching, 50 | ActivityType.Watching, 51 | ActivityType.Listening, 52 | ]; 53 | const status = ["online", "idle", "dnd"]; 54 | 55 | const random = Math.floor(Math.random() * activityName.length); 56 | client.user.setPresence({ 57 | status: status[random], 58 | activities: [{ name: activityName[random], type: activityType[random] }], 59 | }); 60 | } 61 | // Refresh the Info every 15s 62 | setInterval(changeStatus, 15_000); 63 | 64 | // Join to a Voice Channel 65 | function joinVoice() { 66 | joinVoiceChannel({ 67 | channelId: voiceChannel.id, 68 | guildId: voiceChannel.guild.id, 69 | selfDeaf: true, // Also you change it to false for unDeafen in Voice Channel 70 | adapterCreator: voiceChannel.guild.voiceAdapterCreator, 71 | }); 72 | } 73 | setInterval(joinVoice, 30_000); 74 | 75 | // RGB Role (Edit your Role with random color) 76 | function editRole() { 77 | const rgbRole = voiceChannel.guild.roles.cache.get(config.rgbRoleId); 78 | rgbRole.edit({ color: "Random" }); 79 | } 80 | // Edit the Role color every 5 minutes 81 | setInterval(editRole, 300_000); 82 | 83 | console.log( 84 | `Logged in as ${client.user.tag}\nGitHub: https://github.com/calledmasih | Don't forget to ⭐` 85 | ); 86 | }); 87 | 88 | client.on("messageCreate", async (message) => { 89 | // Advanced Ping Command 90 | if (message.content.startsWith(`${config.prefix}ping`)) { 91 | await message.channel.sendTyping(); 92 | const pingEmbed = new EmbedBuilder() 93 | .setTitle(client.user.username + " - Pong!") 94 | .setThumbnail(client.user.displayAvatarURL({ size: 1024 })) 95 | .addFields( 96 | { 97 | name: `🛰 Message Ping:`, 98 | value: `${Date.now() - message.createdTimestamp}ms`, 99 | }, 100 | { 101 | name: `📊 API Latency:`, 102 | value: `${Math.round(client.ws.ping)}ms`, 103 | }, 104 | { 105 | name: `⏳ Uptime:`, 106 | value: ` | `, 109 | } 110 | ) 111 | .setColor(message.guild.members.me.displayHexColor) 112 | 113 | .setFooter({ 114 | text: `Requested by ${message.author.username}`, 115 | iconURL: message.author.displayAvatarURL({ size: 1024 }), 116 | }) 117 | .setTimestamp(); 118 | 119 | message.reply({ 120 | embeds: [pingEmbed], 121 | allowedMentions: { 122 | repliedUser: false, 123 | }, 124 | }); 125 | message.react("✅"); 126 | } 127 | }); 128 | 129 | // Log in to Your Application Bot 130 | client.login(config.botToken); 131 | --------------------------------------------------------------------------------