Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client.guilds.get() not working as intended

I was writing a Discord bot for my friend, and when I was making a rainbow color role feature for him, I stopped on a big error.

First of all, this is my code:

var guild = client.guilds.get("493432486148177923")
var role = guild.roles.get("501752627709870080");
var role2 = guild.roles.get("493436150019784704");
setInterval(() => {
  role.setColor([Math.floor(Math.random() * 255), Math.floor(Math.random() * 255), Math.floor(Math.random() * 255)])
  role2.setColor([Math.floor(Math.random() * 255), Math.floor(Math.random() * 255), Math.floor(Math.random() * 255)])
}, 8000)

All stopped on the guild variable. It was giving out me null/undefined, and when going to guild.roles.get(), it caused my program to crash. I tried using .find() instead of .get() for finding the guild, but this also didn't work.

like image 362
ijnkawakaze Avatar asked Nov 10 '18 18:11

ijnkawakaze


1 Answers

I don't know if you are still searching for an answer but I just encountered the same problem. After a bit of investigation I came up with a solution:

var server = client.guilds.cache.get(serverID);

This works for me. Hope it helps!

like image 100
Y. Georgiev Avatar answered Nov 20 '22 20:11

Y. Georgiev