From 2e498c82a01eb9044d3a0368369a08e2cdd1a11c Mon Sep 17 00:00:00 2001 From: abalabahaha Date: Sun, 15 Nov 2015 11:44:32 -0800 Subject: [PATCH 1/4] Fixed grunt babel path and added --dev option --- gruntfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index ed686b427..a66455ed0 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -8,13 +8,13 @@ module.exports = function (grunt) { babel: { options: { loose: "all", - compact: true + compact: !grunt.option('dev') }, dist: { files: [{ expand: true, cwd: "src/", - src: ["/**/**.*"], + src: ["**/**.*"], dest: "lib/", ext: ".js" }] From 7af104a892bfedf7e60b849e08d44d9f852d11a7 Mon Sep 17 00:00:00 2001 From: abalabahaha Date: Sun, 15 Nov 2015 11:45:35 -0800 Subject: [PATCH 2/4] sendTyping, setStatus, and channel position --- src/Client/Client.js | 54 ++++++++++++++++++++++++- src/Client/InternalClient.js | 71 +++++++++++++++++++++++++++++++-- src/Structures/ServerChannel.js | 1 + 3 files changed, 122 insertions(+), 4 deletions(-) diff --git a/src/Client/Client.js b/src/Client/Client.js index 577bf1aa2..dad38a484 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -29,11 +29,19 @@ class Client extends EventEmitter { get privateChannels(){ return this.internal.private_channels; } - + get voiceConnection(){ return this.internal.voiceConnection; } + get readyTime(){ + return this.internal.readyTime; + } + + get uptime(){ + return this.internal.uptime; + } + // def login login(email, password, cb = function (err, token) { }) { var self = this; @@ -497,6 +505,50 @@ class Client extends EventEmitter { }); } + //def setStatus + setStatus(idleStatus, gameID, callback=function(err){}){ + var self = this; + return new Promise((resolve, reject) => { + if (typeof gameID === "function") { + // gameID is the callback + callback = gameID; + } + else if (typeof idleStatus === "function") { + // idleStatus is the callback + callback = idleStatus; + } + + self.internal.setStatus(idleStatus, gameID) + .then(() => { + callback(); + resolve(); + }) + .catch(e => { + callback(e); + reject(e); + }); + + }) + } + + //def sendTyping + sendTyping(channel, callback=function(err){}){ + var self = this; + return new Promise((resolve, reject) => { + + self.internal.sendTyping(channel) + .then(() => { + callback(); + resolve(); + }) + .catch(e => { + callback(e); + reject(e); + }); + + }) + } + // def setTopic setTopic(channel, topic, callback=function(err){}){ var self = this; diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 0a3c57b2b..6b4996f50 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -42,6 +42,11 @@ class InternalClient { this.private_channels = new Cache(); this.voiceConnection = null; this.resolver = new Resolver(this); + this.readyTime = null; + } + + get uptime() { + return (this.readyTime ? Date.now() - this.readyTime : null); } //def leaveVoiceChannel @@ -699,6 +704,7 @@ class InternalClient { }); } + // def deleteRole deleteRole(role) { var self = this; @@ -910,6 +916,57 @@ class InternalClient { }); } + //def setStatus + setStatus(idleStatus, gameID) { + var self = this; + return new Promise((resolve, reject) => { + + var packet = { + op: 3, + d: { + idle_since: null, + game_id: null + } + }; + + if (idleStatus) { + packet.d.idle_since = Date.now(); + } + if (typeof gameID === "number") { + packet.d.game_id = gameID; + } + + self.sendWS(packet); + + resolve(); + }); + } + + //def sendTyping + sendTyping(channel) { + var self = this; + return new Promise((resolve, reject) => { + + self.resolver.resolveChannel(channel).then(next).catch(reject); + + function next(channel) { + + request + .post(Endpoints.CHANNEL(channel.id) + "/typing") + .set("authorization", self.token) + .end((err, res) => { + if (err) { + reject(err); + } else { + resolve(); + } + }) + + } + + }); + } + //def setTopic setTopic(chann, topic = "") { var self = this; @@ -924,7 +981,7 @@ class InternalClient { .set("authorization", self.token) .send({ name: channel.name, - position: 0, + position: channel.position, topic: topic }) .end((err, res) => { @@ -940,6 +997,7 @@ class InternalClient { }); } + //def setChannelName setChannelName(chann, name = "discordjs_is_the_best") { var self = this; @@ -954,7 +1012,7 @@ class InternalClient { .set("authorization", self.token) .send({ name: name, - position: 0, + position: channel.position, topic: channel.topic }) .end((err, res) => { @@ -970,6 +1028,7 @@ class InternalClient { }); } + //def setChannelNameAndTopic setChannelNameAndTopic(chann, name = "discordjs_is_the_best", topic = "") { var self = this; @@ -984,7 +1043,7 @@ class InternalClient { .set("authorization", self.token) .send({ name: name, - position: 0, + position: channel.position, topic: topic }) .end((err, res) => { @@ -1046,6 +1105,10 @@ class InternalClient { client.emit("disconnected"); } + this.websocket.onerror = (e) => { + console.log(e); + } + this.websocket.onmessage = (e) => { if (e.type === "Binary") { @@ -1082,6 +1145,8 @@ class InternalClient { client.emit("ready"); client.emit("debug", `ready packet took ${Date.now() - startTime}ms to process`); client.emit("debug", `ready with ${self.servers.length} servers, ${self.channels.length} channels and ${self.users.length} users cached.`); + + self.readyTime = Date.now(); break; case PacketType.MESSAGE_CREATE: diff --git a/src/Structures/ServerChannel.js b/src/Structures/ServerChannel.js index d82bfed87..1ee1c73b9 100644 --- a/src/Structures/ServerChannel.js +++ b/src/Structures/ServerChannel.js @@ -10,6 +10,7 @@ class ServerChannel extends Channel{ super(data, client); this.name = data.name; this.type = data.type; + this.position = data.position; this.permissionOverwrites = new Cache(); this.server = server; data.permission_overwrites.forEach((permission) => { From cabb170aeeb5f66692d0304cae7ffdd63e190837 Mon Sep 17 00:00:00 2001 From: abalabahaha Date: Sun, 15 Nov 2015 11:45:54 -0800 Subject: [PATCH 3/4] grunt default does weird things to lib --- lib/Client/Client.js | 55 +++++++++++++++++++- lib/Client/ConnectionState.js | 2 +- lib/Client/InternalClient.js | 72 +++++++++++++++++++++++++-- lib/Client/Resolver/Resolver.js | 2 +- lib/Constants.js | 2 +- lib/Structures/Channel.js | 2 +- lib/Structures/ChannelPermissions.js | 2 +- lib/Structures/Message.js | 2 +- lib/Structures/PMChannel.js | 2 +- lib/Structures/PermissionOverwrite.js | 2 +- lib/Structures/Role.js | 2 +- lib/Structures/Server.js | 2 +- lib/Structures/ServerChannel.js | 3 +- lib/Structures/TextChannel.js | 2 +- lib/Structures/User.js | 2 +- lib/Structures/VoiceChannel.js | 2 +- lib/Util/Cache.js | 2 +- lib/Util/Equality.js | 2 +- lib/Voice/AudioEncoder.js | 2 +- lib/Voice/StreamIntent.js | 2 +- lib/Voice/VoiceConnection.js | 2 +- lib/Voice/VoicePacket.js | 28 +++++------ lib/index.js | 2 +- 23 files changed, 157 insertions(+), 39 deletions(-) diff --git a/lib/Client/Client.js b/lib/Client/Client.js index eb9e09c42..3decf989a 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -509,6 +509,49 @@ var Client = (function (_EventEmitter) { }); }; + //def setStatus + + Client.prototype.setStatus = function setStatus(idleStatus, gameID) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof gameID === "function") { + // gameID is the callback + callback = gameID; + } else if (typeof idleStatus === "function") { + // idleStatus is the callback + callback = idleStatus; + } + + self.internal.setStatus(idleStatus, gameID).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def sendTyping + + Client.prototype.sendTyping = function sendTyping(channel) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.sendTyping(channel).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + // def setTopic Client.prototype.setTopic = function setTopic(channel, topic) { @@ -624,9 +667,19 @@ var Client = (function (_EventEmitter) { get: function get() { return this.internal.voiceConnection; } + }, { + key: "readyTime", + get: function get() { + return this.internal.readyTime; + } + }, { + key: "uptime", + get: function get() { + return this.internal.uptime; + } }]); return Client; })(EventEmitter); -module.exports = Client; \ No newline at end of file +module.exports = Client; diff --git a/lib/Client/ConnectionState.js b/lib/Client/ConnectionState.js index 86fb95261..e0585d77e 100644 --- a/lib/Client/ConnectionState.js +++ b/lib/Client/ConnectionState.js @@ -4,4 +4,4 @@ exports.IDLE = 0; exports.LOGGING_IN = 1; exports.LOGGED_IN = 2; exports.READY = 3; -exports.DISCONNECTED = 4; \ No newline at end of file +exports.DISCONNECTED = 4; diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index e33f14203..d002b2758 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -1,5 +1,7 @@ "use strict"; +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var EventEmitter = require("events"); @@ -46,6 +48,7 @@ var InternalClient = (function () { this.private_channels = new Cache(); this.voiceConnection = null; this.resolver = new Resolver(this); + this.readyTime = null; } //def leaveVoiceChannel @@ -856,6 +859,54 @@ var InternalClient = (function () { }); }; + //def setStatus + + InternalClient.prototype.setStatus = function setStatus(idleStatus, gameID) { + var self = this; + return new Promise(function (resolve, reject) { + + var packet = { + op: 3, + d: { + idle_since: null, + game_id: null + } + }; + + if (idleStatus) { + packet.d.idle_since = Date.now(); + } + if (typeof gameID === "number") { + packet.d.game_id = gameID; + } + + self.sendWS(packet); + + resolve(); + }); + }; + + //def sendTyping + + InternalClient.prototype.sendTyping = function sendTyping(channel) { + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(channel).then(next)["catch"](reject); + + function next(channel) { + + request.post(Endpoints.CHANNEL(channel.id) + "/typing").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } + }); + }; + //def setTopic InternalClient.prototype.setTopic = function setTopic(chann) { @@ -870,7 +921,7 @@ var InternalClient = (function () { request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({ name: channel.name, - position: 0, + position: channel.position, topic: topic }).end(function (err, res) { if (err) { @@ -898,7 +949,7 @@ var InternalClient = (function () { request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({ name: name, - position: 0, + position: channel.position, topic: channel.topic }).end(function (err, res) { if (err) { @@ -927,7 +978,7 @@ var InternalClient = (function () { request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({ name: name, - position: 0, + position: channel.position, topic: topic }).end(function (err, res) { if (err) { @@ -985,6 +1036,10 @@ var InternalClient = (function () { client.emit("disconnected"); }; + this.websocket.onerror = function (e) { + console.log(e); + }; + this.websocket.onmessage = function (e) { if (e.type === "Binary") { @@ -1023,6 +1078,8 @@ var InternalClient = (function () { client.emit("ready"); client.emit("debug", "ready packet took " + (Date.now() - startTime) + "ms to process"); client.emit("debug", "ready with " + self.servers.length + " servers, " + self.channels.length + " channels and " + self.users.length + " users cached."); + + self.readyTime = Date.now(); break; case PacketType.MESSAGE_CREATE: @@ -1368,7 +1425,14 @@ var InternalClient = (function () { }; }; + _createClass(InternalClient, [{ + key: "uptime", + get: function get() { + return this.readyTime ? Date.now() - this.readyTime : null; + } + }]); + return InternalClient; })(); -module.exports = InternalClient; \ No newline at end of file +module.exports = InternalClient; diff --git a/lib/Client/Resolver/Resolver.js b/lib/Client/Resolver/Resolver.js index a0a6e55ca..5463bb5ad 100644 --- a/lib/Client/Resolver/Resolver.js +++ b/lib/Client/Resolver/Resolver.js @@ -182,4 +182,4 @@ var Resolver = (function () { return Resolver; })(); -module.exports = Resolver; \ No newline at end of file +module.exports = Resolver; diff --git a/lib/Constants.js b/lib/Constants.js index 9b1c9b37a..1b341a0b6 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -124,4 +124,4 @@ var PacketType = { exports.API_ENDPOINT = API; exports.Endpoints = Endpoints; exports.PacketType = PacketType; -exports.Permissions = Permissions; \ No newline at end of file +exports.Permissions = Permissions; diff --git a/lib/Structures/Channel.js b/lib/Structures/Channel.js index f8a141584..c348738bb 100644 --- a/lib/Structures/Channel.js +++ b/lib/Structures/Channel.js @@ -22,4 +22,4 @@ var Channel = (function (_Equality) { return Channel; })(Equality); -module.exports = Channel; \ No newline at end of file +module.exports = Channel; diff --git a/lib/Structures/ChannelPermissions.js b/lib/Structures/ChannelPermissions.js index fe7a039fd..0c1b29e93 100644 --- a/lib/Structures/ChannelPermissions.js +++ b/lib/Structures/ChannelPermissions.js @@ -72,4 +72,4 @@ var ChannelPermissions = (function () { return ChannelPermissions; })(); -module.exports = ChannelPermissions; \ No newline at end of file +module.exports = ChannelPermissions; diff --git a/lib/Structures/Message.js b/lib/Structures/Message.js index 86d5a59bd..37d04b4de 100644 --- a/lib/Structures/Message.js +++ b/lib/Structures/Message.js @@ -43,4 +43,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; \ No newline at end of file +module.exports = Message; diff --git a/lib/Structures/PMChannel.js b/lib/Structures/PMChannel.js index dc28d1c66..bd92d7541 100644 --- a/lib/Structures/PMChannel.js +++ b/lib/Structures/PMChannel.js @@ -43,4 +43,4 @@ var PMChannel = (function (_Equality) { return PMChannel; })(Equality); -module.exports = PMChannel; \ No newline at end of file +module.exports = PMChannel; diff --git a/lib/Structures/PermissionOverwrite.js b/lib/Structures/PermissionOverwrite.js index f20d61b7a..99f82bc0b 100644 --- a/lib/Structures/PermissionOverwrite.js +++ b/lib/Structures/PermissionOverwrite.js @@ -83,4 +83,4 @@ var PermissionOverwrite = (function () { return PermissionOverwrite; })(); -module.exports = PermissionOverwrite; \ No newline at end of file +module.exports = PermissionOverwrite; diff --git a/lib/Structures/Role.js b/lib/Structures/Role.js index 048c183cb..21e0f2b88 100644 --- a/lib/Structures/Role.js +++ b/lib/Structures/Role.js @@ -136,4 +136,4 @@ var Role = (function () { return Role; })(); -module.exports = Role; \ No newline at end of file +module.exports = Role; diff --git a/lib/Structures/Server.js b/lib/Structures/Server.js index 7d7320e70..1ef9f1cac 100644 --- a/lib/Structures/Server.js +++ b/lib/Structures/Server.js @@ -166,4 +166,4 @@ var Server = (function (_Equality) { return Server; })(Equality); -module.exports = Server; \ No newline at end of file +module.exports = Server; diff --git a/lib/Structures/ServerChannel.js b/lib/Structures/ServerChannel.js index 215c31232..aa6b87751 100644 --- a/lib/Structures/ServerChannel.js +++ b/lib/Structures/ServerChannel.js @@ -20,6 +20,7 @@ var ServerChannel = (function (_Channel) { _Channel.call(this, data, client); this.name = data.name; this.type = data.type; + this.position = data.position; this.permissionOverwrites = new Cache(); this.server = server; data.permission_overwrites.forEach(function (permission) { @@ -104,4 +105,4 @@ var ServerChannel = (function (_Channel) { return ServerChannel; })(Channel); -module.exports = ServerChannel; \ No newline at end of file +module.exports = ServerChannel; diff --git a/lib/Structures/TextChannel.js b/lib/Structures/TextChannel.js index 897a1b04c..a4e617a7d 100644 --- a/lib/Structures/TextChannel.js +++ b/lib/Structures/TextChannel.js @@ -36,4 +36,4 @@ var TextChannel = (function (_ServerChannel) { return TextChannel; })(ServerChannel); -module.exports = TextChannel; \ No newline at end of file +module.exports = TextChannel; diff --git a/lib/Structures/User.js b/lib/Structures/User.js index 3815089ee..12260a051 100644 --- a/lib/Structures/User.js +++ b/lib/Structures/User.js @@ -55,4 +55,4 @@ var User = (function (_Equality) { return User; })(Equality); -module.exports = User; \ No newline at end of file +module.exports = User; diff --git a/lib/Structures/VoiceChannel.js b/lib/Structures/VoiceChannel.js index 333786b58..b61a9082e 100644 --- a/lib/Structures/VoiceChannel.js +++ b/lib/Structures/VoiceChannel.js @@ -18,4 +18,4 @@ var VoiceChannel = (function (_ServerChannel) { return VoiceChannel; })(ServerChannel); -module.exports = VoiceChannel; \ No newline at end of file +module.exports = VoiceChannel; diff --git a/lib/Util/Cache.js b/lib/Util/Cache.js index fbe4c5853..b08c517f4 100644 --- a/lib/Util/Cache.js +++ b/lib/Util/Cache.js @@ -95,4 +95,4 @@ var Cache = (function (_Array) { return Cache; })(Array); -module.exports = Cache; \ No newline at end of file +module.exports = Cache; diff --git a/lib/Util/Equality.js b/lib/Util/Equality.js index 3288d530a..dd5763f74 100644 --- a/lib/Util/Equality.js +++ b/lib/Util/Equality.js @@ -42,4 +42,4 @@ var Equality = (function () { return Equality; })(); -module.exports = Equality; \ No newline at end of file +module.exports = Equality; diff --git a/lib/Voice/AudioEncoder.js b/lib/Voice/AudioEncoder.js index 517a7cf68..f178f9e2b 100644 --- a/lib/Voice/AudioEncoder.js +++ b/lib/Voice/AudioEncoder.js @@ -126,4 +126,4 @@ var AudioEncoder = (function () { return AudioEncoder; })(); -module.exports = AudioEncoder; \ No newline at end of file +module.exports = AudioEncoder; diff --git a/lib/Voice/StreamIntent.js b/lib/Voice/StreamIntent.js index 97953194c..aa6bb38c4 100644 --- a/lib/Voice/StreamIntent.js +++ b/lib/Voice/StreamIntent.js @@ -19,4 +19,4 @@ var StreamIntent = (function (_EventEmitter) { return StreamIntent; })(EventEmitter); -module.exports = StreamIntent; \ No newline at end of file +module.exports = StreamIntent; diff --git a/lib/Voice/VoiceConnection.js b/lib/Voice/VoiceConnection.js index 4dee53b15..f61b002f6 100644 --- a/lib/Voice/VoiceConnection.js +++ b/lib/Voice/VoiceConnection.js @@ -329,4 +329,4 @@ var VoiceConnection = (function (_EventEmitter) { return VoiceConnection; })(EventEmitter); -module.exports = VoiceConnection; \ No newline at end of file +module.exports = VoiceConnection; diff --git a/lib/Voice/VoicePacket.js b/lib/Voice/VoicePacket.js index 8fa32d5f6..46797646a 100644 --- a/lib/Voice/VoicePacket.js +++ b/lib/Voice/VoicePacket.js @@ -3,24 +3,24 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var VoicePacket = function VoicePacket(data, sequence, time, ssrc) { - _classCallCheck(this, VoicePacket); + _classCallCheck(this, VoicePacket); - var audioBuffer = data, - returnBuffer = new Buffer(audioBuffer.length + 12); + var audioBuffer = data, + returnBuffer = new Buffer(audioBuffer.length + 12); - returnBuffer.fill(0); - returnBuffer[0] = 0x80; - returnBuffer[1] = 0x78; + returnBuffer.fill(0); + returnBuffer[0] = 0x80; + returnBuffer[1] = 0x78; - returnBuffer.writeUIntBE(sequence, 2, 2); - returnBuffer.writeUIntBE(time, 4, 4); - returnBuffer.writeUIntBE(ssrc, 8, 4); + returnBuffer.writeUIntBE(sequence, 2, 2); + returnBuffer.writeUIntBE(time, 4, 4); + returnBuffer.writeUIntBE(ssrc, 8, 4); - for (var i = 0; i < audioBuffer.length; i++) { - returnBuffer[i + 12] = audioBuffer[i]; - } + for (var i = 0; i < audioBuffer.length; i++) { + returnBuffer[i + 12] = audioBuffer[i]; + } - return returnBuffer; + return returnBuffer; }; -module.exports = VoicePacket; \ No newline at end of file +module.exports = VoicePacket; diff --git a/lib/index.js b/lib/index.js index 31c91c19c..b122e469d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,4 +14,4 @@ module.exports = { TextChannel: require("./Structures/TextChannel"), User: require("./Structures/User"), VoiceChannel: require("./Structures/VoiceChannel") -}; \ No newline at end of file +}; From a81c1bbda6f7d2daca9c51ccad3ebd71e417d5a1 Mon Sep 17 00:00:00 2001 From: abalabahaha Date: Tue, 17 Nov 2015 01:31:17 -0800 Subject: [PATCH 4/4] Updated pingpong --- examples/pingpong.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/pingpong.js b/examples/pingpong.js index d5d90588f..4c0f300f6 100644 --- a/examples/pingpong.js +++ b/examples/pingpong.js @@ -1,7 +1,7 @@ /* this bot is a ping pong bot, and every time a message beginning with "ping" is sent, it will reply with - "pong". + "pong!". */ var Discord = require("../"); @@ -11,26 +11,29 @@ var AuthDetails = require("./auth.json"); var bot = new Discord.Client(); +//when the bot is ready bot.on("ready", function () { console.log("Ready to begin! Serving in " + bot.channels.length + " channels"); }); +//when the bot disconnects bot.on("disconnected", function () { - + //alert the console 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) { - 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. 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); } });