0
votes

I want the bot to change the color of the roles and it gives an error

client.guilds.get(servers[index]).roles.find('name', config.roleName).setColor(rainbow[place])
                                 ^

TypeError: Cannot read property 'roles' of undefined
    at Timeout.changeColor [as _onTimeout] (C:\Users\1\Desktop\discord1\Role.js:29:38)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5)

Here is my code:

function changeColor() {
  for (let index = 0; index < servers.length; ++index) {        
    client.guilds.get(servers[index]).roles.find('name', config.roleName).setColor(rainbow[place])
        .catch(console.error);      
    if(config.logging){
      console.log([ColorChanger] Changed color to ${rainbow[place]} in server: ${servers[index]});
    }
    if(place == (size - 1)){
      place = 0;
    }else{
      place++;
    }
  }
}
1

1 Answers

0
votes

You're getting this error because client.guilds.get('<id>') expects an exact guild id passed in as a String. See the comments in red under the .find method:

All collections used in Discord.js are mapped using their id property, and if you want to find by id you should use the get method. See MDN for details.

Therefore, the data stored at server[index] (in the 3rd line of your code) must not be a valid guild id.