discordjs / discord.js

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

channel.permissionOverwrites returns too many arguments. #2944

Closed VirtuesL closed 5 years ago

VirtuesL commented 5 years ago

Please describe the problem you are having in as much detail as possible:

The methods guild#createChannel and channel#clone do not work, throwing out a (node:12252) UnhandledPromiseRejectionWarning: RangeError: Invalid permission string or number.

This seems to be because the <channel>.permissionOverwrites returns 6 arguments instead of 4. To be exact it returns allowed, and denied. According to discord API documentation it only accepts 4 arguments.

Include a reproducible code sample here, if possible:


// Place your code here
message.channel.clone()
//or
message.guild.createChannel(<name>, "text",  message.channel.permissionOverwrites)

Further details:

Dionysusnu commented 5 years ago

Bumping this because I'm getting the error again My code:

module.exports = {
    name: 'purge',
    description: 'Removes a number of messages in a channel',
    args: true,
    guildOnly: true,
    async execute(message, args) {
        // console.log(message.client)
        const authorguildmember = message.guild.members.find(member => member.id === message.author.id);
        if (!authorguildmember.hasPermission('MANAGE_MESSAGES')) return message.channel.send('You are not allowed to delete messages');
        const clientguildmember = message.guild.members.find(member => member.id === message.client.user.id);
        if (!clientguildmember.hasPermission('MANAGE_MESSAGES')) return message.channel.send('I don\'t have the manage messages permission!');
        if (!(parseInt(args[0]) || (args[0]) === 'all')) return message.channel.send('Please enter a valid number between 1 and 99');
        if (args[0] === 'all') {
// ERROR OCCURS ON LINE BELOW
            const newchannel = await message.channel.clone(undefined, true, true, 'purged all');
            message.channel.send(`Please move to ${newchannel}, this channel will be deleted`);
            setTimeout(message.channel.delete, 3000, ['Purged']);
        } else {
            let amountToDelete = parseInt(args[0]) + 1;
            while (amountToDelete) {
                if (amountToDelete >= 100) {
                    message.channel.bulkDelete(100, true);
                    amountToDelete -= 100;
                } else {
                    message.channel.bulkDelete(amountToDelete, true);
                    amountToDelete = 0;
                }
            }
        }
    },
};

So, as the original post mentions, it's very likely the TextChannel.clone() function. Error:

RangeError: Invalid permission string or number.
    at Function.resolve (/app/node_modules/discord.js/src/util/Permissions.js:194:65)
    at overwrites.map.overwrite (/app/node_modules/discord.js/src/structures/shared/resolvePermissions.js:18:27)
    at Map.map (/app/node_modules/discord.js/src/util/Collection.js:343:47)
    at RESTMethods.resolvePermissions (/app/node_modules/discord.js/src/structures/shared/resolvePermissions.js:6:29)
    at RESTMethods.createChannel (/app/node_modules/discord.js/src/client/rest/RESTMethods.js:260:49)
    at Guild.createChannel (/app/node_modules/discord.js/src/structures/Guild.js:1004:37)
    at TextChannel.clone (/app/node_modules/discord.js/src/structures/GuildChannel.js:401:23)
    at Object.execute (/app/commands/purge.js:14:45)
    at Client.client.on.message (/app/index.js:198:10)
    at Client.emit (events.js:198:13)

Further details: discord.js version: 11.4.2 Node.js version: v10.16.0 OS: heroku cloud Priority: medium Bot account, Have not tested issue on latest master, will do now.

SpaceEEC commented 5 years ago

Since you are on 11.4.2 try updating to 11.5.1, this sounds like a bug which was fixed there. See the relevant changelog entry:

  • Permissions.resolve not accepting a Permissions instance (5d889be6db65acc44f3a443b78d3165f9d6c0ed2)