Reputation: 922
I'm currently playing around with Nodes.js
and creating a simple bot as a proof on concept. I'm using the discord.js
package.
I have the following codes
// FluffBot class initialisation
var FluffBot = function Constructor(settings, commands) {
this.settings = settings
this.commands = commands
}
// Run bot
FluffBot.prototype.run = function() {
discord = new discord.Client()
discord.loginWithToken(this.settings.bot_token)
discord.on('ready', function(event) {
FluffBot._onReady(event)
})
}
// On ready function
FluffBot.prototype._onReady = function(event) {
discord.setPlayingGame('Alpha v1.0')
this.watcher()
}
I am initiating the run function in another js file but am getting the following error
TypeError: FluffBot._onReady is not a function at Client.<anonymous>
Any ideas on getting it to call the function would be awesome.
Upvotes: 0
Views: 1193
Reputation: 9105
Are you sure FluffBot is is instantiated with the new
keyword?
You could add this to prevent:
if (!(this instanceof FluffBot)) {
return new FluffBot()
}
Upvotes: 1