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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With