{"id":15042246,"url":"https://github.com/sachinl0har/discord.js-v12-bot-tutorial","last_synced_at":"2025-04-14T20:31:23.734Z","repository":{"id":41781852,"uuid":"355382559","full_name":"sachinl0har/Discord.js-V12-Bot-Tutorial","owner":"sachinl0har","description":"An Discord bot build in Discord.js V12. Features :- Anime, Chatbot, Fun, Info, Moderation, Music, Developer commands and many more coming soon.","archived":false,"fork":false,"pushed_at":"2022-12-12T05:15:01.000Z","size":466,"stargazers_count":51,"open_issues_count":2,"forks_count":17,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T09:03:00.084Z","etag":null,"topics":["discord","discord-api","discord-js","discordapp","nodejs"],"latest_commit_sha":null,"homepage":"https://acronoid.sachinlohar.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sachinl0har.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2021-04-07T01:59:15.000Z","updated_at":"2025-02-13T07:21:38.000Z","dependencies_parsed_at":"2023-01-27T14:01:02.785Z","dependency_job_id":null,"html_url":"https://github.com/sachinl0har/Discord.js-V12-Bot-Tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sachinl0har%2FDiscord.js-V12-Bot-Tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sachinl0har%2FDiscord.js-V12-Bot-Tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sachinl0har%2FDiscord.js-V12-Bot-Tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sachinl0har%2FDiscord.js-V12-Bot-Tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sachinl0har","download_url":"https://codeload.github.com/sachinl0har/Discord.js-V12-Bot-Tutorial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248955538,"owners_count":21189154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-api","discord-js","discordapp","nodejs"],"created_at":"2024-09-24T20:47:02.086Z","updated_at":"2025-04-14T20:31:23.136Z","avatar_url":"https://github.com/sachinl0har.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Discord.js-V12-Bot-Tutorial](https://socialify.git.ci/sachinl0har/Discord.js-V12-Bot-Tutorial/image?description=1\u0026font=Source%20Code%20Pro\u0026forks=1\u0026issues=1\u0026language=1\u0026owner=1\u0026pattern=Plus\u0026pulls=1\u0026stargazers=1\u0026theme=Dark)\n# Discord.js-Tutorial\n\nHere is a Discord.js Bot Tutorial.\n![forthebadge](https://forthebadge.com/images/badges/made-with-javascript.svg)\n\n## Getting Started\n\nFor Getting Started you should atleast have a basic knowledge of JavaScript. Basic Knowledge means you should know the basic functions and Syntax's.\n\n### Prerequisites and Installing Softwares\n\nFirst you need to download the latest verison of [Node.js](https://nodejs.org/en/) after installing, if you want to check if node.js is installed in your computer or not. go to the search bar and type `CMD` open it and type `node --version` in the terminal it should show you the latest verison which you installed.\nSecond you need a code editor i recommend you [Visual Studio Code](https://code.visualstudio.com/download), Then after installation open Visual Studio Code and go to Extensions and download the extension of JavaScript.\n\n### Create Discord Application\n\nGo to [Discord Developer Portal](https://discord.com/developers/applications) And click \"New Application\" And then name your application then click \"Create\" .Now , Head over to Bot. Click Add Bot, then you customize the name and avatar(If youd like). Now lets get coding.\n\n### Coding\n\nMake a folder where you want to store all your bot files. Open CMD with that Folder location and type `npm init` This will create a `package.json` file in your directory.Then open Visual Studio Code with that Directory.then make a file with your main file name, in my case its `alpha.js` then type this code \n```js\n// IMPORT MAIN FILES AND PACKAGES WHICH IS REQUIRED.\nconst Discord = require('discord.js');\nconst config = require('./configs/config.json'); // AS YOU SEE YOU HAVE TO MAKE A FOLDER NAMED `configs` AND IN THAT FOLDER MAKE `config.json` FILE. CODE WILL BE GIVEN ABOVE.\nconst fs = require('fs');\nconst db = require('quick.db');\nconst path = require(\"path\");\nconst client = new Discord.Client();\nclient.commands = new Discord.Collection();\nclient.aliases = new Discord.Collection();\nconst { Player } = require('discord-player');\nconst player = new Player(client);\nclient.player = player;\nclient.emotes = require('./configs/emotes.json')\nclient.filters = require('./configs/filters.json');\n[\"aliases\", \"commands\"].forEach(cmd =\u003e client[cmd] = new Discord.Collection());\n[\"console\", \"command\", \"event\"].forEach(events =\u003e require(`./handlers/${events}`)(client));\nclient.categories = fs.readdirSync('./commands');\n// EVENTS\nclient.on('ready', async() =\u003e {\n    console.log('Alpha Started!');\n});\nclient.login(config.token)\n```\n\nConfig File\n```js\n{\n    \"prefix\": \"your prefix here\",    \n    \"dev\": \"736977089307345004\", // DEVELOEPRS ID HERE      \n    \"token\": \"bot token here\"     \n}\n```\n\n### Command Handler\ncommand.js // READ FILES INSIDE COMMANDS FOLDER\n```js\nconst fs = require('fs');\nmodule.exports = (client) =\u003e {\n    const load = dirs =\u003e {\n        const commands = fs.readdirSync(`./commands/${dirs}/`).filter(cmd =\u003e cmd.endsWith('.js'));\n        for (let cmd of commands) {\n            let pull = require(`../commands/${dirs}/${cmd}`);\n            client.commands.set(pull.config.name, pull);\n            if (pull.config.aliases) pull.config.aliases.forEach(cmd =\u003e client.aliases.set(cmd, pull.config.name));\n        };\n    };\n    [\"Folder Names Inside Commands folder\"].forEach(cmd =\u003e load(cmd));\n};\n```\n\n### Event Handler\nevent.js // READ EVENT FILES    \n```js\nconst fs = require('fs');\nmodule.exports = (client) =\u003e {\n    const load = dirs =\u003e {\n        const events = fs.readdirSync(`./events/${dirs}`).filter(events =\u003e events.endsWith('.js'));\n        for (let file of events) {\n            const events = require(`../events/${dirs}/${file}`);\n            let eventName = file.split('.')[0];\n            client.on(eventName, events.bind(null,client));\n        };\n    };\n    ['client', 'guild'].forEach(events =\u003e load(events));\n};\n```\n\n### Bot Status and Activity\n```js\nlet totalUsers = client.guilds.cache.reduce((users , value) =\u003e users + value.memberCount, 0);\n    let totalGuilds = client.guilds.cache.size\n    let totalChannels = client.channels.cache.size\n    client.user.setPresence({ activity: { name: `${totalUsers} Users | ${totalGuilds} Servers | ${totalChannels} Channels`, type: \"PLAYING\" }, status: \"online\" });\n ```\n \n### Command Structure\n```js\nconst Discord = require('discord.js');\nconst config = require('../../configs/config.json');\nmodule.exports = {\n    config: {\n        name: '',\n        description: '',\n        aliases: [\"\"],\n        usage: '',\n        accessableby: \"\",\n    },\n    run: async (client, message, args) =\u003e {\n     // PROCESSING CODE HERE\n    }\n}\n```\n\n### ChatBot Feature For a Specific Channel\n```\nvar chatbot = new alexa(\"chat bot api\"); //YOUR CHATBOT API HERE\n```\n\n```js\nclient.on(\"message\", async message =\u003e {\n        let sChannel = db.fetch(`chatbot_${message.guild.id}`);\n        if (sChannel === null) {\n            return;\n          }\n            if (message.author.bot \u0026\u0026 message.author.discriminator !== '0000') return;\n            if(message.channel.id === sChannel){\n                let content = message.content;\n                if(!content) return;\n                    chatbot.getReply(content).then(r =\u003e client.channels.cache.get(sChannel).send(r));\n            }\n         });\n```\n\n\n## More Advanced commands will be added soon stay tunned and follow. And if this was helpfull i will be glad if you give it a Star.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsachinl0har%2Fdiscord.js-v12-bot-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsachinl0har%2Fdiscord.js-v12-bot-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsachinl0har%2Fdiscord.js-v12-bot-tutorial/lists"}