Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

Set Role Color for Discord.js bot

I am trying to make my bot's role a pink color for the current server using the Client.on("ready") However whenever I run the bot with what I currently have the console returns:

(node:6504) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'cache' of undefined

Here is my code I am currently using. I know I need to for loop on every guild but I'm not sure how I would do that, I could use a for or just a .forEach however I can't find the correct way to do such.

const role = client.guild.roles.cache.get('Aiz Basic+');  
role.edit({ name: 'Aiz Basic+', color: '#FFC0CB' });

In advance thank you to anybody who replies and helps with my message.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this code if client.guild is not defined, it could also be because you are using bot instead of client

let role = message.guild.roles.cache.find(role => role.name === "Aiz Basic+");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...