Search code examples
node.jsdiscord.js

TypeError: Discord.Permissions is not a constructor


There’s this error i get after i try to login to discord using my bot’s dashboard: > TypeError: Discord.Permissions is not a constructor

Code:

const _perms = guild.permissions_new;
                const _checkBot = client.guilds.cache.get(guild.id);
                _guilds[index].bot_added = _checkBot ? true : false;
                _guilds[index].permissions = new Discord.Permissions(_perms).toArray();
            });

            delete _user.accessToken;
            _user.permissions = _dbUser ? _dbUser.permissions : [];
            _user.notifications = _dbUser ? _dbUser.notifications : [];
            _user.connections = {};
            _user.guilds = _guilds;

Any help would be appreciated. 🙏

I tried to log in my discord bot’s website dashboard via discord connection, while expecting it to work, it just opened up a discord authorization page that doesn’t let you do anything while being refreshed in loop


Solution

  • When in doubt, check the documentation.

    Permissions isn't there. Therefore, one shouldn't expect this to work. There is PermissionsBitField, however, and running console.log(new PermissionsBitField(8n).toArray()); returns ["Administrator"]. This is likely what you are looking for.

    I searched this specific piece of code in GitHub and found 3 results of which all seem to be the same copy of code and which all appear to be using discord.js 13.x. What very likely happened here is you installed discord.js 14.x (as such is the current latest stable version) and ran version 13 code on it. Unfortunately, this will not work (as evident). There is an update guide you should browse through.