Discord.js: Inconsistent behavior of permissionOverwrites for channel

Created on 25 Aug 2020  Â·  1Comment  Â·  Source: discordjs/discord.js

Issue:
permissionOverwrites key for channel creations' object throw invalid userID/roleID even if I feed it through native functions like guild.ownerID.

Erroneous code:

    guild.channels.create('channelName', {
      type: 'text',
      reason: 'reason,
      parent: parentChannel,
      permissionOverwrites: [
        {
          id: guild.roles.cache.find(role => role.name == 'Players'),
          deny: ['VIEW_CHANNEL']
        },
         // Throws an error here:
         {
           id: 'ASSUME_A_VALID_USERID', // throws even if the I pass guild.ownerID
           allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES']
         }
      ]
    })

Error message:
TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
at Function.resolve (..node_modules\discord.js\src\structures\PermissionOverwrites.js:177:28)
at ..node_modules\discord.js\src\managers\GuildChannelManager.js:109:81
at Array.map ()
at GuildChannelManager.create (..node_modules\discord.js\src\managers\GuildChannelManager.js:109:51)
at ..\main.js:62:20
at processTicksAndRejections (internal/process/task_queues.js:97:5)
{
}

Further details:

  • discord.js version: 12.3.1
  • Node.js version: 12.18.3
  • Operating system: Windows 10
  • Priority this issue should have – please be realistic and elaborate if possible:

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none
  • [ ] I have also tested the issue on latest master, commit hash:
unverified bug

Most helpful comment

Cannot reproduce.


Code used

(12.3.1)

const client = new (require('discord.js').Client)()
const { token } = require('./config.js');

client.on('ready', () => {
  const guild = client.guilds.cache.get('334499698075238401');
  const parentChannel = guild.channels.cache.get('553725317085396995');

  guild.channels.create('channelName', {
    type: 'text',
    reason: 'reason',
    parent: parentChannel,
    permissionOverwrites: [
      {
        id: guild.roles.cache.find(role => role.name == 'Absolute Mad Lad'), // Role name is correct
        deny: ['VIEW_CHANNEL']
      },
      {
        id: '245867108582293504', // guild.ownerID works as well
        allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES']
      }
    ]
  })
});

client.login(token);


No matter if user ID is passed directly or via guild.ownerID, this part works.
Same applies to first overwrite, works no matter if i pass ID or a Role object.

Only times it errored was when:

  • passed ID was incorrect;
  • the roles.cache.find() function did not find anything (e.g. a typo in role name, like Absolute MadLad), returning undefined instead of Role object.

>All comments

Cannot reproduce.


Code used

(12.3.1)

const client = new (require('discord.js').Client)()
const { token } = require('./config.js');

client.on('ready', () => {
  const guild = client.guilds.cache.get('334499698075238401');
  const parentChannel = guild.channels.cache.get('553725317085396995');

  guild.channels.create('channelName', {
    type: 'text',
    reason: 'reason',
    parent: parentChannel,
    permissionOverwrites: [
      {
        id: guild.roles.cache.find(role => role.name == 'Absolute Mad Lad'), // Role name is correct
        deny: ['VIEW_CHANNEL']
      },
      {
        id: '245867108582293504', // guild.ownerID works as well
        allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES']
      }
    ]
  })
});

client.login(token);


No matter if user ID is passed directly or via guild.ownerID, this part works.
Same applies to first overwrite, works no matter if i pass ID or a Role object.

Only times it errored was when:

  • passed ID was incorrect;
  • the roles.cache.find() function did not find anything (e.g. a typo in role name, like Absolute MadLad), returning undefined instead of Role object.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

LLamaFTL picture LLamaFTL  Â·  3Comments

ghost picture ghost  Â·  3Comments

ghost picture ghost  Â·  3Comments

shukriadams picture shukriadams  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments