My Code:
const Discord = require(‘discord.io’, ‘discord.js’);
var logger = require(‘winston’);
var auth = require(’./auth.json’);
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = ‘debug’;
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
bot.on(‘ready’, function (evt) {
logger.info(‘Connected’);
logger.info(‘Logged in as: ‘);
logger.info(bot.username + ’ - (’ + bot.id + ‘)’);
console.log(‘Launched Bot Successfully…’);
});
bot.on(‘ready’, () => { – I have tried all sorts of things here, and none work. This is my first bot too so please excuse the mess
bot.user.setPresence({ game: { name: ‘with discord.js’ }, status: ‘idle’ })
.then(console.log)
.catch(console.error);
})
bot.on(‘message’, function (user, userID, channelID, message, evt) {
if (message.substring(0, 1) == ‘!’) {
var args = message.substring(1).split(’ ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
case 'launchtest':
bot.sendMessage({
to: channelID,
message: 'Launch successful!'
});
break;
}
}
});
Error I’m getting:
PS C:\Users\Lenovo E531\Desktop\DiscordTimeBot> node bot.js
{“message”:“Connected”,“level”:“info”}
{“message”:"Logged in as: ",“level”:“info”}
{“message”:“Current Time Bot - (592169374320951322)”,“level”:“info”}
Launched Bot Successfully… --This means its up, status and presence no however.
C:\Users\Lenovo E531\Desktop\DiscordTimeBot\bot.js:20
bot.user.setPresence({ game: { name: ‘with discord.js’ }, status: ‘idle’ })
^
TypeError: Cannot read property ‘setPresence’ of undefined
at DiscordClient.bot.on (C:\Users\Lenovo E531\Desktop\DiscordTimeBot\bot.js:20:14)
at DiscordClient.emit (events.js:203:15)
at Timeout.checkForAllServers [as _onTimeout] (C:\Users\Lenovo E531\node_modules\discord.io\lib\index.js:1729:66)
at ontimeout (timers.js:438:13)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)