mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
32 lines
783 B
JavaScript
32 lines
783 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* A ping pong bot, whenever you send "ping", it replies "pong".
|
|
*/
|
|
|
|
// Import the discord.js module
|
|
const Discord = require('discord.js');
|
|
|
|
// Create an instance of a Discord client
|
|
const client = new Discord.Client();
|
|
|
|
/**
|
|
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
|
* received from Discord
|
|
*/
|
|
client.on('ready', () => {
|
|
console.log('I am ready!');
|
|
});
|
|
|
|
// Create an event listener for messages
|
|
client.on('message', message => {
|
|
// If the message is "ping"
|
|
if (message.content === 'ping') {
|
|
// Send "pong" to the same channel
|
|
message.channel.send('pong');
|
|
}
|
|
});
|
|
|
|
// Log our bot in using the token from https://discord.com/developers/applications/me
|
|
client.login('your token here');
|