discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.47k stars 3.97k forks source link

setPosition bug #6381

Closed McDefault closed 3 years ago

McDefault commented 3 years ago

Please describe the problem you are having in as much detail as possible: It seems like setPosition is putting the position on -1 resulting in an DiscordAPIError;

https://discord.js.org/#/docs/main/13.0.1/class/GuildChannel?scrollTo=setPosition

Include a reproducible code sample here, if possible:

        console.log(position); //returns 10
        await channel.delete("Channel Nuked by Maxminded Bot.");
        const newChannel = await channel.clone().catch(err => console.error(err));
        await newChannel.setPosition(position).catch(() => {
        });

Error:

 DiscordAPIError: Invalid Form Body
 position: int32 value should be greater than or equal to 0.
     at RequestHandler.execute (/usr/src/bot/node_modules/discord.js/src/rest/RequestHandler.js:298:13)
     at processTicksAndRejections (node:internal/process/task_queues:96:5)
     at async RequestHandler.push (/usr/src/bot/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
     at async GuildChannelManager.create (/usr/src/bot/node_modules/discord.js/src/managers/GuildChannelManager.js:142:18)
     at async GuildController.Nuke (/usr/src/bot/src/controllers/GuildController.js:544:28)
     at async Object.exports.interaction (/usr/src/bot/src/commands/nuke.js:86:32) {
   method: 'post',
   path: '/guilds/281874979191259136/channels',
   code: 50035,
   httpStatus: 400,
   requestData: {
     json: {
       name: '234',
       topic: null,
       type: 0,
       nsfw: false,
       bitrate: undefined,
       user_limit: undefined,
       parent_id: '701806668845154454',
       position: -1,
       permission_overwrites: [Array],
       rate_limit_per_user: 0
     },
     files: []
   }
 }

Further details:

Relevant client options:

McDefault commented 3 years ago

after a few tests i concluded that the v13 no longer allows to clone deleted channels while the v12 did, which resulted in my issue.

Fix is putting clone BEFORE delete