discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Role color not changing using role.edit(). [No errors thrown] #5957

Closed jaipack17 closed 3 years ago

jaipack17 commented 3 years ago

Stumbled upon this issue today. Tried changing role color of a role in my server but it fails to change using discord.js. No errors are thrown in console.

Include a reproducible code sample here, if possible:

function changeRoleColor() {
  let role = client.guilds.cache.get("846219248044343336").roles.cache.get("858718455477174312"); //not undefined.
  let randomColorHex = Math.floor(Math.random()*16777215).toString(16); //valid hexcode is chosen.

  role.edit({
    color: `#${randomColorHex}` //used to change the color earlier. fails to do it now. 
  })
}

changeRoleColor()

No errors are thrown but discord doesn't update the role color. Bot has the required permissions to edit the role. And everything seemed to work yesterday. Today, it just doesn't. Tried refreshing discord a few times to see if my cache updates but nope. Doesn't change the color. Trying .catch(err => console.log(err)) will also not throw the error.

Further details:

Relevant client options:

tipakA commented 3 years ago

Can't seem to reproduce on 12.5.2. (Technically equal to 12.5.3 in this case)

Used this eval code ```js const output = {}; const role = message.guild.roles.cache.get('642286689246511114'); output.oldColor = role.color; let randomColor = Math.floor(Math.random() * 16777215).toString(16); output.randomColor = randomColor; role.edit({ color: `#${randomColor}` }) .then(r => { output.newColor = r.color; return output; }); // Running that returned { oldColor: 13302178, randomColor: '22907f', newColor: 2265215 } // and role did correctly change the color in client. ```
jaipack17 commented 3 years ago
let role = client.guilds.cache.get("846219248044343336").roles.cache.get("858718455477174312");
console.log(role.color)
let randomColorHex = Math.floor(Math.random()*16777215).toString(16);

role.edit({ color: `#${randomColorHex}` }).then(r => {
  console.log(r.color)
})

Logging role color before change returns 13181643 which is the current color set in the server.

Logging the role color after change returns 13181643 the same color which was set before changing the role color. So the role color isn't really changed.

And it also isn't an issue with randomColorHex. I have logged it to the console several times. And it returns a valid random hexadecimal number.

Also the same code worked perfectly earlier.

jaipack17 commented 3 years ago

Tried out your evaluation code as well. Prints the same role color, and doesn't change it.

jaipack17 commented 3 years ago

Welp, seems like I reached the 1000 requests per 24 hours role editing ratelimit. Thats the reason why it doesn't work. Thanks.