1const Discord = require('discord.js') //this says that its using discord.js and classifing it as a bot
2const bot = new Discord.Client();
3
4const token = 'put your bots token here!';
5//link to the dev portal to make your own discord bot here: https://discord.com/developers/applications
1// npm install discord.js
2// Download node.js first if you can't install the discord.js depedencies
3const Discord = require('discord.js')
4const client = new Discord.client()
5
6// You can store the prefix in a JSON file and access it
7// by destructuring it's object property
8const {
9 prefix // let's assume it is "!" as the prefix
10 token // DO NOT SHARE THAT TO ANYONE IN ANYWAY. You can get that on your Discord bot developer page.
11} = require('./<filename>.json') // as an example
12
13client.on("ready", () => {
14 console.log('Ready!')
15})
16
17client.on("message", message => {
18 // if the message DOES NOT (!) starts with the prefix then the bot will not respond
19 if (!message.content.startsWith(prefix)) return;
20
21 // Here, ping is a template litteral which is an useful way to format declared values with strings
22 if (message.content === `${prefix}ping`) { // !ping -> bot respond: Pong
23 message.channel.send("Pong")
24 }
25}
26
27client.login(token) // Your token as stored in a JSON file.
28
1const Discord = require('discord.js');
2const client = new Discord.Client();
3const token = 'YOUR TOKEN HERE'; // For get a token , go here https://discord.com/developers/applications
4
5client.login(token);
1/* If you are a mac user, do this in TERMINAL
2If you are a Window/Linux user, do this in COMMAND PROMPT
3
4npm install discord.js
5
6DISCORD.JS IS NOW INSTALLED.
7I suggest looking on youtube for a tutorial on setting up a project, but here are the basics.
8
9
10THIS CODE SHOULD BE IN A "index.js" or "main.js" or whatever your main file is.*/
11
12const Discord = require('discord.js');
13const client - new Discord.Client();
14const /*you can have any prefix you want here*/ prefix = "?"
15
16client.on("ready", () => {
17 console.log('literally anything you want goes here')
18})
19
20//SUPER BASIC COMMAND: BASICALLY SHOWS THAT YOUR BOT CAN SPEAK
21client.on('message', message => {
22 if(message.content.startsWith(`${prefix}ping`)){
23 message.channel.send('pong!');
24 }
25})
26
27
28//EXTREMELY IMPORTANT: GET YOUR TOKEN FROM THE DISCORD DEVELOPER PORTAL
29//NEVER EVER EVER EVER TELL/GIVE ANYONE YOUR TOKEN!
30client.login('your token here');