mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Updated pingpong
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
this bot is a ping pong bot, and every time a message
|
this bot is a ping pong bot, and every time a message
|
||||||
beginning with "ping" is sent, it will reply with
|
beginning with "ping" is sent, it will reply with
|
||||||
"pong".
|
"pong!".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Discord = require("../");
|
var Discord = require("../");
|
||||||
@@ -11,26 +11,29 @@ var AuthDetails = require("./auth.json");
|
|||||||
|
|
||||||
var bot = new Discord.Client();
|
var bot = new Discord.Client();
|
||||||
|
|
||||||
|
//when the bot is ready
|
||||||
bot.on("ready", function () {
|
bot.on("ready", function () {
|
||||||
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
|
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//when the bot disconnects
|
||||||
bot.on("disconnected", function () {
|
bot.on("disconnected", function () {
|
||||||
|
//alert the console
|
||||||
console.log("Disconnected!");
|
console.log("Disconnected!");
|
||||||
process.exit(1); //exit node.js with an error
|
|
||||||
|
//exit node.js with an error
|
||||||
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//when the bot receives a message
|
||||||
bot.on("message", function (msg) {
|
bot.on("message", function (msg) {
|
||||||
if (msg.content.substring(0, 4) === "ping") {
|
//if message begins with "ping"
|
||||||
|
if (msg.content.indexOf("ping") === 0) {
|
||||||
//send a message to the channel the ping message was sent in.
|
//send a message to the channel the ping message was sent in.
|
||||||
bot.sendMessage(msg.channel, "pong!");
|
bot.sendMessage(msg.channel, "pong!");
|
||||||
|
|
||||||
//alert the console
|
|
||||||
console.log("pong-ed " + msg.sender.username);
|
|
||||||
|
|
||||||
|
//alert the console
|
||||||
|
console.log("pong-ed " + msg.author.username);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user