Role Creation Problem

Despite the title, there are actually no error messages at all. I am trying to have my bot create roles on server join (guildCreate), and the really strange thing about this code is that it was actually working perfectly until it just started either only making the first few roles and then eventually stopping short or just not making any roles at all. I suspect I may be getting ratelimited so I decided to wait a full hour before continuing, but I'm still facing the same issue.
16 Replies
d.js toolkit
d.js toolkit3w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
gian
gianOP3w ago
client.on('guildCreate', async serv => {
for(let i=0;i<role_names.length;++i){
let options = {
name: role_names[i]
};
if(colors[i]) options.color = colors[i];
try{
let role = await serv.roles.create(options);
console.log(role.name);
}catch(error){console.log(error);}
}
});
client.on('guildCreate', async serv => {
for(let i=0;i<role_names.length;++i){
let options = {
name: role_names[i]
};
if(colors[i]) options.color = colors[i];
try{
let role = await serv.roles.create(options);
console.log(role.name);
}catch(error){console.log(error);}
}
});
This is the relevant code segment. I'm running discord.js version 14.16.3. To reiterate, there is no output whatsoever.
Amgelo
Amgelo3w ago
you're most likely getting ratelimited, assuming role_names isn't empty you can double check by listening to the rateLimited event in the rest instance
client.rest.on('rateLimited', console.log)
client.rest.on('rateLimited', console.log)
gian
gianOP3w ago
it's not; it's a length-52 collection
Amgelo
Amgelo3w ago
yeah that's way too high, that'll hit a ratelimit in no time
gian
gianOP3w ago
My bot doesn't see a whole lot of use and hardly ever joins new servers so I figured this wouldn't be an issue. For what it's worth it probably won't be once this goes live. I may tell users to create the roles themselves in case it fails to do so for them
Amgelo
Amgelo3w ago
double check with the event, but I'm pretty sure it's that
gian
gianOP3w ago
yeah sorry let me do that now yeah, it's printing some json object. expected to be honest was just hoping it wouldn't be the issue :PepeHands:
Amgelo
Amgelo3w ago
52 roles is way too high lol
gian
gianOP3w ago
as it is right now my bot generates approximately ten and i haven't had issues in the past
Amgelo
Amgelo3w ago
there isn't anything you can do except wait and maybe reconsider what you're doing, whether you really need that, etc
gian
gianOP3w ago
it's not negotiable unfortunately this is part of the primary feature to be added in my bot's next update so i think i might just call the update off one more question: how can i interpret retryAfter? I can't seem to find anything on the json object in this event in the documentation not really, just sort of assumed since its ability to do so is its "selling point" if you will. i do not see how this has any bearing on the issue in question then it will promptly not function as intended under such circumstances. if it encounters any non-ratelimit issues (permissions problems, role limits, what have you) in creating a role, it just moves on I've already said it so i'm going to repeat myself since it seems like it needs to be said: the discussion of the motivation for having it written in this way is not relevant to the issue in question all I need is an answer to this then I will be on my way.
Amgelo
Amgelo3w ago
I mean, if we knew more about your problem we can also provide workarounds or better alternatives to avoid an https://xyproblem.info but anyways you don't need to handle that, the rest client already does it
gian
gianOP3w ago
If I needed alternatives I would have made a separate post after you answered my initial question :-)
Amgelo
Amgelo3w ago
most people don't know when they need alternatives
gian
gianOP3w ago
Sorry, let me be a little more clear: in this very instant I do not care. I might care in a few hours. Or not. I don't know. I will try to think about workarounds when I can but right now it's easier to just stop what i'm doing and roll back changes to the last commit I had before I started working on this I would also like to let it be said that I was already considering alternatives before either of you prompted me to do so. Regardless, it is nice to have closure on this problem; i just wanted to be absolutely certain that it was just getting ratelimited. Thank you Amgelo.

Did you find this page helpful?