Answers for "discord.js guide"

2

discord.js start code

const Discord = require('discord.js') //this says that its using discord.js and classifing it as a bot
const bot = new Discord.Client();

const token = 'put your bots token here!';
//link to the dev portal to make your own discord bot here: https://discord.com/developers/applications
Posted by: Guest on May-07-2020
1

discord.js guide

// npm install discord.js
// Download node.js first if you can't install the discord.js depedencies
const Discord = require('discord.js') 
const client = new Discord.client()

// You can store the prefix in a JSON file and access it 
// by destructuring it's object property
const {
  prefix // let's assume it is "!" as the prefix
  token // DO NOT SHARE THAT TO ANYONE IN ANYWAY. You can get that on your Discord bot developer page.
} = require('./<filename>.json') // as an example

client.on("ready", () => {
  console.log('Ready!')
})

client.on("message", message => {
  // if the message DOES NOT (!) starts with the prefix then the bot will not respond
  if (!message.content.startsWith(prefix)) return;
  
	// Here, ping is a template litteral which is an useful way to format declared values with strings
  if (message.content === `${prefix}ping`) { // !ping -> bot respond: Pong
    message.channel.send("Pong")
  }
}

client.login(token) // Your token as stored in a JSON file.
Posted by: Guest on March-11-2021
2

discord.js start

const Discord = require('discord.js');
const client = new Discord.Client();
const token = 'YOUR TOKEN HERE'; // For get a token , go here https://discord.com/developers/applications

client.login(token);
Posted by: Guest on July-06-2020
0

discord.js download

/* If you are a mac user, do this in TERMINAL
If you are a Window/Linux user, do this in COMMAND PROMPT

npm install discord.js 

DISCORD.JS IS NOW INSTALLED.
I suggest looking on youtube for a tutorial on setting up a project, but here are the basics.


THIS CODE SHOULD BE IN A "index.js" or "main.js" or whatever your main file is.*/

const Discord = require('discord.js');
const client - new Discord.Client();
const /*you can have any prefix you want here*/ prefix = "?"

client.on("ready", () => {
	console.log('literally anything you want goes here')
})

//SUPER BASIC COMMAND: BASICALLY SHOWS THAT YOUR BOT CAN SPEAK
client.on('message', message => {
	if(message.content.startsWith(`${prefix}ping`)){
    	message.channel.send('pong!');
    }
})


//EXTREMELY IMPORTANT: GET YOUR TOKEN FROM THE DISCORD DEVELOPER PORTAL
//NEVER EVER EVER EVER TELL/GIVE ANYONE YOUR TOKEN!
client.login('your token here');
Posted by: Guest on September-14-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language