Discord.js: [GUILD_CHANNEL_ORPHAN]: Could not find a parent to this guild channel.

Created on 29 Mar 2020  Â·  9Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
Created a category and channel on the guildCreate event, set the channel parent to the category and tried to lockPermissions(), It failed saying it could not find a parent to this guild channel.
It does put the channel as a child to the category as can be seen here:
image
But when it comes to locking permissions, It fails.
Include a reproducible code sample here, if possible:

// Place your code here

let modRole = await guild.roles.cache.find(r => r.name === 'Moderator'); // Check for logs channel - If not found, create it! const staffArea = guild.channels.cache.find(channel => channel.name === 'Staff Area'); if(!staffArea){ try { guild.channels.create('Staff Area', { type : 'category', topic : 'Staff Area', permissionOverwrites : [{ id : modRole.id, allow : ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'MANAGE_MESSAGES','EMBED_LINKS', 'ATTACH_FILES'] }, { id : guild.id, deny : ['VIEW_CHANNEL'] }], }) console.log('Staff Area created!'); } catch (error){ console.log(error) } } const modLogs = await guild.channels.cache.find(channel => channel.name === 'modlogs'); if(!modLogs){ try{ guild.channels.create('modlogs', { type: 'text', topic: 'Logs Channel' }).then(async channel => { let staff = guild.channels.cache.find(c => c.name == "Staff Area" && c.type == "category"); if (!staff){ console.log("Staff Area not found!"); } await channel.setParent(staff.id) await channel.lockPermissions() console.log("Staff area built and roles assigned"); }) } catch (error){ console.log(error) } }
Further details:
I believe this may be due to the API not updating properly, as can be seen in this report:
https://github.com/discordjs/discord.js/issues/2644

  • discord.js version: v12
  • Node.js version: V12.13.1
  • Operating system: Windows 10 Dev | Ubuntu Production
  • Priority this issue should have – please be realistic and elaborate if possible:
    Unsure, but if your not able to lockPermissions() after setParent() then it should be specified

  • [] I have also tested the issue on latest master, commit hash:

unverified bug

All 9 comments

Can you try await channel.setParent(staff.id).then(x => { console.log("Parent set!") x.lockPermissions() }).catch(err => { console.log("An error occured.") })

This issue is caused by the aforementioned issue listed above, as the command is executing faster than the bot updating the cache by gateway events. A simple solution would be using the setTimeout() method provided by the Client structure.

Can you try await channel.setParent(staff.id).then(x => { console.log("Parent set!") x.lockPermissions() }).catch(err => { console.log("An error occured.") })

That worked no errors, I presume it's not a bug but more down to my logic?

Unable to reproduce this with the sample shown below.

    message.guild.channels.create("test-channel", {
      type: 'text',
      topic: 'Used for testing'
    })
    .then(async (channel) => {

      const parent = await message.guild.channels.create("parent-for-testing", {
         type: 'category' ,
         permissionOverwrites: [
           {
             id: message.guild.id,
             allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
             deny: ['ADD_REACTIONS']
           }
         ]
       });

      await channel.setParent(parent.id);
      await channel.lockPermissions();
    })

@SketchyLxve Interesting, create the channel and then the category...

Will close this, as it's been resolved by the code provided by @sbaliq and also a non-reproducable version by @SketchyLxve therefore most likely down to my code.

I've got a quick question, @Tricky-Ricky, what if you roll back to some version like v12.0.1? Does the issue still persist? Or is it just present for you on v12.1.1?


I think this is just an issue with logic.
When doing GuildChannelManager#create, then using the value from the resolved promise, which is GuildChannel, calling setParent on it will set the parent, yes, but it, GuildChannel#setParent(), returns a modified clone of it, it doesn't directly modify that channel where the returned value will have a new parent property. Thus, calling lockPermissions on it will fail as the returned value has no parent property (since you haven't provided a parent ID upon creating the channel in the options object).

A small work-around for this would be to do something like:

await (await channel.setParent(id)).lockPermissions()

// or

// as Sbaliq suggested
channel.setParent(id)
   .then(async (ch) => {
        await ch.lockPermissions()
   })

The above error happens with my code on v12.0.1 - But again the code from @sbaliq works in v12.0.1

That is because the value you defined channel as does not change when you use the .setParent() method.
Resolving the promise using .then() returns the modified/patched clone of the channel, which is then able to use the .lockPermissions() method as mentioned above.

Not much we can do PR wise as this would be considered a breaking change, so you can suggest this again once v13 is ready for PR's and such.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xCuzImPro picture xCuzImPro  Â·  3Comments

ghost picture ghost  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

Lombra picture Lombra  Â·  3Comments

BrandonCookeDev picture BrandonCookeDev  Â·  3Comments