All Projects → sachinl0har → Discord.js-V12-Bot-Tutorial

sachinl0har / Discord.js-V12-Bot-Tutorial

Licence: other
An Discord bot build in Discord.js V12. Features :- Anime, Chatbot, Fun, Info, Moderation, Music, Developer commands and many more coming soon.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Discord.js-V12-Bot-Tutorial

Karuma
Karuma is a Discord Bot including Nukes, Raids, Mass DM and other features. Only for educational purposes 🥱🚀
Stars: ✭ 132 (+186.96%)
Mutual labels:  discordapp, discord-api, discord-js
Aometry
An awesome multipurpose discord bot build using discord.js v13 with support for slash commands and context menus
Stars: ✭ 51 (+10.87%)
Mutual labels:  discordapp, discord-api, discord-js
mass-dm-discord
A MassDM selfbot which is working in 2021. Only for educational purposes 🥱🚀
Stars: ✭ 87 (+89.13%)
Mutual labels:  discordapp, discord-api, discord-js
discord-voice
⏲️ A complete framework to facilitate the tracking of user voice time using discord.js
Stars: ✭ 33 (-28.26%)
Mutual labels:  discordapp, discord-api, discord-js
Discord-Reposter
Bot for reposting Discord messages (work in progress)
Stars: ✭ 62 (+34.78%)
Mutual labels:  discordapp, discord-api, discord-js
framework
✨ A framework for creating discord bots build with discord.js. Modular | Flexible | Powerful | Development | Interactions
Stars: ✭ 41 (-10.87%)
Mutual labels:  discordapp, discord-api, discord-js
Luki
[Deprecated] The official repository for Luki the Discord bot
Stars: ✭ 21 (-54.35%)
Mutual labels:  discordapp, discord-api, discord-js
Discord-Selfbot
Discord.js selfbot
Stars: ✭ 24 (-47.83%)
Mutual labels:  discordapp, discord-api, discord-js
Discord-Rich-Presence-Party-Mode
Discord Rich Presence Tool. Party Mode | Cycle Mode integrated. The first to do it.
Stars: ✭ 18 (-60.87%)
Mutual labels:  discordapp, discord-api, discord-js
LenoxBot
🖥️ LenoxBot is a Discord bot that offers many cool new features to your Discord server!
Stars: ✭ 218 (+373.91%)
Mutual labels:  discordapp, discord-api, discord-js
DM-BOT
📧 DM-BOT is discord bot that can record direct messages. One of us! You can also reply to those messages! DM-BOT is easy to use & understand! I decided to use Discord.js, it's literally the best.
Stars: ✭ 31 (-32.61%)
Mutual labels:  discordapp, discord-js
DiscordBot-Template
A boilerplate / template for discord.js bots with 100% coverage of Discord API, command handler, error handler based on https://discordjs.guide/
Stars: ✭ 129 (+180.43%)
Mutual labels:  discord-api, discord-js
suggestions-bot
A Discord bot designed to build better communities by encouraging a positive and constructive relationship between community and staff.
Stars: ✭ 22 (-52.17%)
Mutual labels:  discord-api, discord-js
discord-message-handler
Message and command handler for discord.js bots and applications
Stars: ✭ 19 (-58.7%)
Mutual labels:  discord-api, discord-js
auto
A code scanner Discord bot.
Stars: ✭ 15 (-67.39%)
Mutual labels:  discord-api, discord-js
Commando
[DEPRECATED] ⚫ Commando Discord bot built on discord.js-commando.
Stars: ✭ 78 (+69.57%)
Mutual labels:  discord-api, discord-js
ALi
ALi a powerful Discord bot that includes Utility, Fun, Music, Moderation, and much more! (Beta)
Stars: ✭ 97 (+110.87%)
Mutual labels:  discordapp, discord-js
SataniaBot
The most devilish bot for Discord!
Stars: ✭ 20 (-56.52%)
Mutual labels:  discord-api, discord-js
Discord-BOT-Dashboard
This version is outdated, please check out Discord BOT Dashboard v2
Stars: ✭ 32 (-30.43%)
Mutual labels:  discord-api, discord-js
discord.bat
🗑️ the BEST discord lib
Stars: ✭ 38 (-17.39%)
Mutual labels:  discordapp, discord-api

Discord.js-V12-Bot-Tutorial

Discord.js-Tutorial

Here is a Discord.js Bot Tutorial. forthebadge

Getting Started

For Getting Started you should atleast have a basic knowledge of JavaScript. Basic Knowledge means you should know the basic functions and Syntax's.

Prerequisites and Installing Softwares

First you need to download the latest verison of Node.js 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. Second you need a code editor i recommend you Visual Studio Code, Then after installation open Visual Studio Code and go to Extensions and download the extension of JavaScript.

Create Discord Application

Go to Discord Developer Portal 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.

Coding

Make 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

// IMPORT MAIN FILES AND PACKAGES WHICH IS REQUIRED.
const Discord = require('discord.js');
const 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.
const fs = require('fs');
const db = require('quick.db');
const path = require("path");
const client = new Discord.Client();
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
const { Player } = require('discord-player');
const player = new Player(client);
client.player = player;
client.emotes = require('./configs/emotes.json')
client.filters = require('./configs/filters.json');
["aliases", "commands"].forEach(cmd => client[cmd] = new Discord.Collection());
["console", "command", "event"].forEach(events => require(`./handlers/${events}`)(client));
client.categories = fs.readdirSync('./commands');
// EVENTS
client.on('ready', async() => {
    console.log('Alpha Started!');
});
client.login(config.token)

Config File

{
    "prefix": "your prefix here",    
    "dev": "736977089307345004", // DEVELOEPRS ID HERE      
    "token": "bot token here"     
}

Command Handler

command.js // READ FILES INSIDE COMMANDS FOLDER

const fs = require('fs');
module.exports = (client) => {
    const load = dirs => {
        const commands = fs.readdirSync(`./commands/${dirs}/`).filter(cmd => cmd.endsWith('.js'));
        for (let cmd of commands) {
            let pull = require(`../commands/${dirs}/${cmd}`);
            client.commands.set(pull.config.name, pull);
            if (pull.config.aliases) pull.config.aliases.forEach(cmd => client.aliases.set(cmd, pull.config.name));
        };
    };
    ["Folder Names Inside Commands folder"].forEach(cmd => load(cmd));
};

Event Handler

event.js // READ EVENT FILES

const fs = require('fs');
module.exports = (client) => {
    const load = dirs => {
        const events = fs.readdirSync(`./events/${dirs}`).filter(events => events.endsWith('.js'));
        for (let file of events) {
            const events = require(`../events/${dirs}/${file}`);
            let eventName = file.split('.')[0];
            client.on(eventName, events.bind(null,client));
        };
    };
    ['client', 'guild'].forEach(events => load(events));
};

Bot Status and Activity

let totalUsers = client.guilds.cache.reduce((users , value) => users + value.memberCount, 0);
    let totalGuilds = client.guilds.cache.size
    let totalChannels = client.channels.cache.size
    client.user.setPresence({ activity: { name: `${totalUsers} Users | ${totalGuilds} Servers | ${totalChannels} Channels`, type: "PLAYING" }, status: "online" });

Command Structure

const Discord = require('discord.js');
const config = require('../../configs/config.json');
module.exports = {
    config: {
        name: '',
        description: '',
        aliases: [""],
        usage: '',
        accessableby: "",
    },
    run: async (client, message, args) => {
     // PROCESSING CODE HERE
    }
}

ChatBot Feature For a Specific Channel

var chatbot = new alexa("chat bot api"); //YOUR CHATBOT API HERE
client.on("message", async message => {
        let sChannel = db.fetch(`chatbot_${message.guild.id}`);
        if (sChannel === null) {
            return;
          }
            if (message.author.bot && message.author.discriminator !== '0000') return;
            if(message.channel.id === sChannel){
                let content = message.content;
                if(!content) return;
                    chatbot.getReply(content).then(r => client.channels.cache.get(sChannel).send(r));
            }
         });

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].