TypeError: Cannot read property 'channels' of undefined

Hello, why do I get this error?
TypeError: Cannot read property ‘channels’ of undefined

var Discord = require(‘discord.js’);
var client = new Discord.Client();
const axios = require(“axios”);
var request = require(‘request’);

client.on(‘ready’, () => {
setInterval(() => {
return request(“https://api.trackyserver.com/widget/index.php?id=606814”, (err, response, body) => {
if (err) throw(err);
var data = JSON.parse(body);
client.user.setActivity(data.playerscount + ’ online’);
let guild = client.guilds.cache.get(700967388379742318);
let channel = guild.channels.get(754993174954508308)
channel.setName('Players: ’ + data.playerscount)
.then(newChannel => console.log(Channel's new name is ${newChannel.name}))
.catch(console.error);
});
}, 10000); // Runs this every 10 seconds.
});

client.login(‘NzAyOTAwOTg1NzI2NTAwODg0.XqGxjg.’);

Hi @carlohera! Welcome to the forums!
2 things:

  1. You might want to change your bot token and get rid of it from your original post, otherwise people could hack your bot.
  2. Can you try replacing
let guild = client.guilds.cache.get(700967388379742318);

With

let guild = client.guilds.cache.get('700967388379742318');

Because it needs to be a string rather than a number. Same with guild.channels.get(754993174954508308)' - put quotes around the number.
If that doesn’t work, make sure the ids are correct.

3 Likes

Also here’s the prettyprinted code:

var Discord = require(‘discord.js’);
var client = new Discord.Client();
const axios = require(“axios”);
var request = require(‘request’);
client.on(‘ready’, () => {
			setInterval(() => {
				return request(“https: //api.trackyserver.com/widget/index.php?id=606814”, (err, response, body) => {
					if (err) throw (err);
					var data = JSON.parse(body); client.user.setActivity(data.playerscount + ’online’);
					let guild = client.guilds.cache.get(700967388379742318);
					let channel = guild.channels.get(754993174954508308)
					channel.setName('Players: ’ + data.playerscount).then(newChannel => console.log(Channel 's new name is ${newChannel.name})).catch(console.error);
						});
					}, 10000); // Runs this every 10 seconds.
			});
			client.login(‘process.env.TOKEN’);