How to make sure that a channels.create call followed by a channels.fetch call is consistent?

Right now I have some code that creates a category and then adds some channels to it. What I've noticed is that there is some sort of race condition. Whenever I create a new category with
await guild.channels.create({
type: ChannelType.GuildCategory,
name: groupToCreate,
});
await guild.channels.create({
type: ChannelType.GuildCategory,
name: groupToCreate,
});
then there is a seemingly random chance that a subsequent
await guild.channels.fetch();
await guild.channels.fetch();
call will not contain the newly created category. How can i make sure that fetch is in a happens-before relationship with create? Note that I also tried:
await guild.channels.fetch(undefined, {
force: true,
});
await guild.channels.fetch(undefined, {
force: true,
});
to no avail. 😦
3 Replies
d.js toolkit
d.js toolkitβ€’16mo 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! - βœ… Marked as resolved by OP
πŸŒΊπŸ‡«πŸ‡· Shigu :3 🌺
why can't you save the created category in a variable to reuse it?
addamsson
addamssonOPβ€’16mo ago
i figured it out i'm creating channels in parallel and there is a race condition
Want results from more Discord servers?
Add your server