Create Discord Bot in Glitch With V12 of Discord.js 1

Create Discord Bot in Glitch With V12 of Discord.js

As i am here with re creation discord.js with stable version of discord.js, There is few changes in discord.js v12 , So now i am gonna show you how to create discord bot using discord.js stable version.

Go to glitch.com and create project and select Hellow express, Make sure your package.json look like this –

{
  "//1": "describes your app and its dependencies",
  "//2": "https://docs.npmjs.com/files/package.json",
  "//3": "updating this file will download and update your packages",
  "name": "hello-express",
  "version": "0.0.1",
  "description": "A simple Node app built on Express, instantly up and running.",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.17.1"
  },
  "engines": {
    "node": "12.x"
  },
  "repository": {
    "url": "https://glitch.com/edit/#!/hello-express"
  },
  "license": "MIT",
  "keywords": [
    "node",
    "glitch",
    "express"
  ]
}

Go to server.js and follow below steps 🙂

Logging in Discord

const Discord = require('discord.js'); //Needed discord.js module
const client = new Discord.Client(); //Creating Discord new client

client.once('ready', () => { //When bot is ready , bot will run given code
	console.log('Ready!'); //Sends Ready to console as message
  client.user.setActivity(`I am Devil`); //Sets bot activity as "I am Devil" 
});

client.login('your-token-goes-here'); //Paste Your Bot Token

It wont run until you install discord.js module from console, for that type npm i discord.js in glitch Terminal.

Replying To User Message

client.on("message", message => { //when Someone message 
  if(message.content === "!ping") { //if message is same as !ping
    return message.channel.send(`Pong ${client.ws.ping}`); //it will return message
  }
});

Thats how you can send message :), It will reply to message

Resulting Code

Here is the resulting code – https://github.com/CTK-WARRIOR/Guide-discord.js-v12/tree/master/Day-1

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *