Channel's position properties appear to be incoherent

Channel room-2 is positionally above channel room-1. But the cache shows that room-2's rawPosition is 0, and it's position is 1. room-1's rawPosition also shows 0, and it's position shows 0 as well; but it is clearly in position 1 not 0. I'm owner in this server, no channels are hidden.
const guild = bot.guilds.cache.get(`1100538270263291904`),
room2 = guild.channels.cache.get(`1121985572538417164`),
room1 = guild.channels.cache.get(`1121985276923875370`)

console.log(room2.rawPosition, room2.position)
console.log(room1.rawPosition, room1.position)

// result:
0 1
0 0

// expected result
0 0
1 1
const guild = bot.guilds.cache.get(`1100538270263291904`),
room2 = guild.channels.cache.get(`1121985572538417164`),
room1 = guild.channels.cache.get(`1121985276923875370`)

console.log(room2.rawPosition, room2.position)
console.log(room1.rawPosition, room1.position)

// result:
0 1
0 0

// expected result
0 0
1 1
Any ideas? Trying to determine the actual position of channels and I was thinking I could piece something together by using either position, rawPosition or a combination of the two.
17 Replies
d.js toolkit
d.js toolkit12mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
ninbura
ninbura12mo ago
djs version - 14.11.0 node version - 19.9.0
ninbura
ninbura12mo ago
I may be mistaken, but this appears to only be happening when I use the setParent() function on the channel. When someone joins room-1 I grab room-2 from an "inactive voice" category and move it to "active voice" so there's always an open room for people to join. When I use setParent() on room-2 to change its category, that's when it would appear that these positional properties report incorrect position. If I manually move the channel from one category to the other via Discord's GUI it looks like positional propteries are making more sense. Of course, this doesn't solve my problem, because I do want the bot to move the channel. I don't want to move them manually. Just tried manually fetching channels for a guild in-hopes that that would update the cache and fix the issue, but that does nothing. Positional properties continue to report incorrect positions.
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
ninbura
ninbura12mo ago
const bot = new Client({
partials: [Partials.Channel, Partials.Message, Partials.Reaction],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.MessageContent,
],
})
const bot = new Client({
partials: [Partials.Channel, Partials.Message, Partials.Reaction],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.MessageContent,
],
})
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
ninbura
ninbura12mo ago
No problem, I'll be surprised if anyone understands tbh. Feels like it must be a bug in djs or the api.
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
ninbura
ninbura12mo ago
The goal is to listen for the channelUpdate event, and re-sort channels when the channel's parent changes. But I first compare what I think the positions should be to what the positions are. In this case I think room-2 should be in position 1, but the cache's reporting that it's already in that position so I skip sorting them. If I bypass this check they sort into the proper positions, but I can't always bypass the check or the function would loop and spam the api. In the case of the code in the OP I'm logging this information in the ready event. And I've tried putting guild.channels.fetch() before I start grabbing room-1 & 2 to no avail. I also think that cache updates when the bot starts, so that should be redundant. Just a sanity check that the cache just is reporting improper positions. Whether that be djs' or the api's fault.
Syjalo
Syjalo12mo ago
Can't repro
ninbura
ninbura12mo ago
Did you catch the part where I said it only seems to be happening when I use the setParent() method? If I manually move a channel from one cateogry to another the positions are sane, but if I move a channel from one category to another with my bot the positional properties are not updating properly.
Syjalo
Syjalo12mo ago
Yes. I also tried to change the parent in many ways with .setParent() and the position handles correctly
ninbura
ninbura12mo ago
Interestingly, I just deleted room-2 and recreated it and now when I use setParent() it relocates the channel to the bottom of the new parent instead of the top which is what it was doing previously.... maybe this was the problem 🤔 When you use setParent() do your channels relocated to the bottom or the top of the new parent?
Syjalo
Syjalo12mo ago
Now I got an issue in channelUpdate. But some later the position shows correctly. You can create an issue on GitHub.
ninbura
ninbura12mo ago
It's almost like a channel can remember a previous position on a previous parent... Look at this, if I use setParent() to move room-2 to active voice it relocates to the second position, but if I move room-3 it relocates the the bottom of the new parent. I can't seem to understand why they wouldn't both re-locate to the bottom of the category.
ninbura
ninbura12mo ago
I believe it ultimately has something to do with the bot moving channels from one parent to another. I think somehow a channels position is remembered in a previous parent. It may be when the bot moves the channel from one parent to another, and then back again, which is what I'm doing. When the voice channel is "inactive" (no members connected) I use the bot to move it to "inactive channels". when the channel become active (1 or more members connected) again I move it back to "active voice".
ninbura
ninbura12mo ago
I opened an issue on the djs github repo, hopefully I structured it well enough: https://github.com/discordjs/discord.js/issues/9668
GitHub
Channel's positional properties are incoherent when a channel is re...
Which package is this bug report for? discord.js Issue description When a channel is moved from one parent to another parent and back/forth it seems to retain it's position form a previous stat...