setActivity/setPresence not working (undefined)

My Code:
const Discord = require(‘’, ‘discord.js’);
var logger = require(‘winston’);
var auth = require(’./auth.json’);
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) {‘Connected’);‘Logged in as: ‘); + ’ - (’ + + ‘)’);
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’ })
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':
                to: channelID,
                message: 'Launch successful!'


Error I’m getting:
PS C:\Users\Lenovo E531\Desktop\DiscordTimeBot> node bot.js
{“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 (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\\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)

This is offtopic. But in your code you define your bot token like this:

var auth = require('./auth.json');
var bot = new Discord.Client({
	token: auth.token,
	autorun: true

This is bad because your token is not secure there.

Try using enviroment variables.

Modify your .env file


Then in your bot.js file

var bot = new Discord.Client({
	token: process.env.TOKEN,
	autorun: true

Then I tried your function of bot.on('ready', ...) with my bot (using discord.js) and it work.

I don’t know why you have and discord.js in the same variable. I’ve never saw that. Maybe you should choose one. I’m talking about your first line is not supported. Kindly switch over to discord.js

1 Like