Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rolemanager Create Role #7695

Closed
ghost opened this issue Mar 20, 2022 · 9 comments
Closed

Rolemanager Create Role #7695

ghost opened this issue Mar 20, 2022 · 9 comments

Comments

@ghost
Copy link

ghost commented Mar 20, 2022

Which package is this bug report for?

discord.js

Issue description

open: https://discord.js.org/#/docs/discord.js/stable/class/RoleManager?scrollTo=create

Take the code below:
guild.roles.create({
name: 'Test role 1',
color: 'BLUE',
reason: 'Test role',
})
.then(console.log)
.catch(console.error);

It just creates a role called 'new role' without any of the specified fields.

Code sample

guild.roles.create({
  name: 'Test role 1',
  color: 'BLUE',
  reason: 'Test role',
})
  .then(console.log)
  .catch(console.error);

Package version

13.0.0

Node.js version

v16.14.0

Operating system

Windows 10

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

User, GuildMember

Which gateway intents are you subscribing to?

Guilds, GuildMembers

I have tested this issue on a development release

2297c2b

@Jiralite
Copy link
Member

I am unable to reproduce this.

@ghost
Copy link
Author

ghost commented Mar 20, 2022

The bot doesnt create a role with the name or color

@almostSouji
Copy link
Member

I can somewhat reproduce that the color is off on 2297c2b . However, that is consistent with the new example https://discord.js.org/#/docs/discord.js/main/class/RoleManager?scrollTo=create and documentation https://discord.js.org/#/docs/discord.js/main/typedef/ColorResolvable which clearly states "hex string".

static resolveColor(color) {
if (typeof color === 'string') {
if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1));
if (color === 'Default') return 0;
color = Colors[color] ?? parseInt(color.replace('#', ''), 16);
} else if (Array.isArray(color)) {
color = (color[0] << 16) + (color[1] << 8) + color[2];
}
if (color < 0 || color > 0xffffff) throw new RangeError('COLOR_RANGE');
else if (Number.isNaN(color)) throw new TypeError('COLOR_CONVERT');
return color;
}

Accordingly, BLUE is looked up in the Colors object , not found because of the casing difference, and parsed as a hex string.
Due to how JS parses numbers, "123a" would parse as 123. Accordingly, in hex colors BLUEparses as B, which is 11, which results in a black'ish role color, rather than the wanted blue.

I cannot reproduce this on either the linked stable version (you should probably update to 13.6.0, by the way, minor releases are non-breaking) or 2297c2b (if adapted accordingly).

@ghost
Copy link
Author

ghost commented Mar 22, 2022

The code was an example from the discord.js.org documentation for creating a role. However it does not assign it the name i've given it. I've told this already.

@almostSouji
Copy link
Member

We cannot reproduce this behavior on either of the two versions you specified.

@ghost
Copy link
Author

ghost commented Mar 24, 2022

So you're saying the bot created a role with the name you gave it? Because thats what I made this about.

@Jiralite
Copy link
Member

Correct. I would suggest showing a minimum reproducible sample ensuring discord.js is freshly installed (remove it then install it again).

@ghost ghost closed this as completed Mar 26, 2022
@johnnymorris
Copy link

I actually encounter the same issue using the same code, however there is (I believe) a bug.

Whilst first attempting to get this working, my bot created around 250 roles and then I was given an error saying I could not create anymore roles. after manually deleting the roles, and confirming my bot was still working to create a couple of additional roles, I continue with the development of my bot.

Going forward I notice my bot was no longer creating roles (around 2 hours later). I've since spent all night and all day today, reviewing my code, going back to the example above (and in the documentation) even going as far as re-granting permissions, still no joy, I have literally been scratching my head for over 12 hours. As a last attempt I created a new discord server, and it worked (without changing anything other than the discordID my bot is targeting)

Strangly I can manually create a new role using the discord web interface in the original discord server, but when using the API it simply does not create, does not give any response and simply stops. Example Code:

console.log("We should be creating a new role");
role_tribe = await guildlink.roles.create({
name: "MyRole",
color: '#0080FF',
reason: 'Used to grant access to the my channel'
});
console.log("finished");

I receive the first output but never receive the second output when it does not create the rule. I also tried using .then but same issue, it just does not return a response (almost like we are stuck waiting on a promise being filled.

I've tested this a second time by swtiching my bot back to the original server (where it has the issue) after testing it worked in a new discord server. I can't explain why I can create a role in the GUI but not via the API.

@nyapat
Copy link
Contributor

nyapat commented Jun 9, 2022

sounds more like an API issue than discord.js, and if that's the case there's nothing that can be done on the side of the library. I think you may be able to get some success making an issue on d-api-docs

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants