This extremely condensed tutorial shows the steps for getting a Discord bot up and running using Node.js and Discord.js.
- Register a new Bot application at the Discord Developer Portal.
- Download and install Node.js for your platform. Make sure to also install npm.
- Create a new folder on your computer for the bot's files.
- Open a command prompt, cd to the folder, and run
npm init
. Follow the instructions, or press enter for all lines.
- Create a new file
index.js
. On *nix systems, you can do this with touch index.js
- With your terminal still in the folder, run
npm install discord.js
-
Paste this starter code into
index.js
(also available on the the official docs.)
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`${client.user.tag} logged in`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
Download sample code
- Replace
token
with your bot's token.
- Run
node index.js
to launch your bot
Ultra condensed
- Register bot.
- Download Node.js.
mkdir discordbot && cd "$_"
npm init -y
npm install discord.js
wget https://www.ravbug.com/tutorials/discordjs/index.js
- Replace
token
, run node index.js
Super-Ultra condensed
-
Register bot and download Node.js.
-
Replace the
folder
and token
variables at the beginning as appropriate.
folder=discordbot && token=your_token_here; mkdir $folder && cd "$_" && npm init -y && npm install discord.js && wget https://www.ravbug.com/tutorials/discordjs/index.js && sed "s/'token'/'$token'/g" index.js
-
node index.js