Discord.js: channel's .setPosition() doesn't work properly

Created on 25 Feb 2017  Â·  6Comments  Â·  Source: discordjs/discord.js

I needed to move a channel to the first slot, but when I use .setPosition(1) it moves to the second slot and .setPosition(0) to the last slot.

already fixed

Most helpful comment

This isn't a problem with the library, this is either a Discord bug or an intentional feature.

When you're reordering channels with the API and not your normal client, the position property of every channel can be anything you want it to. They don't have to be consecutive numbers, they can share the same position number and can even be negative.

The Discord client just renders the channel in ascending order by their position number. I don't know if this is a bug, or if this is the way they meant it to be. But it's not very practical for developers, as positional numbers can vary on each guild.

All 6 comments

that is intentional, as in javascript — and most programming languages — lists start at 0 not 1

This isn't a problem with the library, this is either a Discord bug or an intentional feature.

When you're reordering channels with the API and not your normal client, the position property of every channel can be anything you want it to. They don't have to be consecutive numbers, they can share the same position number and can even be negative.

The Discord client just renders the channel in ascending order by their position number. I don't know if this is a bug, or if this is the way they meant it to be. But it's not very practical for developers, as positional numbers can vary on each guild.

To add to the above, when you reorder channels within the client by dragging, Discord is sending a request to /guild/guildID/channels with a payload of every channel being updated by the move, which includes their new positional value. (I'm not sure if the client would ever send a single channel update request that also modifies the position, even though they document it in the API.)

If you want to make sure your channel positions don't get messed up, you could handle that in a way that mimics the client using updateChannels and some filtering, but there's nothing in the library right now that checks if you're screwing your channel positions up by setting them to the same index.

discord builds an index on channel reorder much like how we do here with roles: https://github.com/hydrabolt/discord.js/pull/1211/files#diff-e5c54069adfa0d32480eb3cc9faeee20R889

i could add something similar for channels if it is necessary.

@GusCaplan I talked with @Gawdl3y about that yesterday and he said that this would be preferable yes.
Something along the lines of "we should do the same thing as we do with roles."

added to my pr #1211

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smchase picture smchase  Â·  3Comments

PassTheMayo picture PassTheMayo  Â·  3Comments

DatMayo picture DatMayo  Â·  3Comments

shukriadams picture shukriadams  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments