DiscordJS example bot

Free lines JavaScript 1 revisions 742 3 years ago 3 years ago
const Discord = require('discord.js');

const bot = new Discord.Client();
const token = '<token>';
const prefix = '!';

bot.on('ready', () => {
	console.log(`Logged in as ${bot.user.username}!`);

bot.on('message', msg => {
	// You probably here want a more sophisticated command parser
	// As well as command handler
	if (msg.content.startsWith(prefix)) {
		if (msg.content.startsWith(prefix + 'ping')) {


This is the most basic example of a JavaScript Discord bot using the DiscordJS library.

You need to go to your Discord apps page, create an application, make it a bot one, and then replace the token in the code above. The code should be directly runnable.