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:
Relevant client options:
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:
roles.cache.find() function did not find anything (e.g. a typo in role name, like Absolute MadLad), returning undefined instead of Role object.
Most helpful comment
Cannot reproduce.
Code used
(12.3.1)
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:
roles.cache.find()function did not find anything (e.g. a typo in role name, likeAbsolute MadLad), returningundefinedinstead of Role object.