Reputation: 99
If I press the button, the following error occurs: TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
However, I can also put a solid id there and this error still occurs.
button.guild.channels.create('cs', {
type: "text",
parent_id: '802172599836213258',
permissionOverwrites: [
{
id: button.guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
},
{
id: button.clicker.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
}
]
})
Upvotes: 0
Views: 751
Reputation: 5605
In DiscordJS 13 (maybe previous version as well), you must passed the type parameter for it to work if the role/user is not yet cached.
button.guild.channels.create('cs', {
type: "text",
parent_id: '802172599836213258',
permissionOverwrites: [
{
id: button.guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
},
{
id: button.clicker.id,
type: "member",
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
}
]
})
The reason why it does not work without the type
is due to this code when creating a channel:
https://github.com/discordjs/discord.js/blob/34ba9d1c4c80eff7e6ac199a40232d07491432cc/packages/discord.js/src/structures/PermissionOverwrites.js#L183
if (typeof overwrite.id === 'string' && overwrite.type in OverwriteType) {
return {
id: overwrite.id,
type: overwrite.type,
allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.DefaultBit).toString(),
deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.DefaultBit).toString(),
};
}
const userOrRole = guild.roles.resolve(overwrite.id) ?? guild.client.users.resolve(overwrite.id);
if (!userOrRole) throw new TypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
const type = userOrRole instanceof Role ? OverwriteType.Role : OverwriteType.Member;
And here when using the PermissionOverwriteManager
:
async upsert(userOrRole, options, overwriteOptions = {}, existing) {
let userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
let { type, reason } = overwriteOptions;
if (typeof type !== 'number') {
userOrRole = this.channel.guild.roles.resolve(userOrRole) ?? this.client.users.resolve(userOrRole);
if (!userOrRole) throw new TypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
type = userOrRole instanceof Role ? OverwriteType.Role : OverwriteType.Member;
}
....
If type
is not given, then it will try to call this.client.role.resolve
and this.client.users.resolve
which will only check the cache.
Either update your cache by fetching the user/role, or precise the type to avoid to have to check the cache.
Upvotes: 1
Reputation: 320
The only possible problem I can see is the button.guild.roles.everyone
, there's no everyone property in button.guild.roles
, the everyone id is the guild id, so if you replace button.guild.roles.everyone
with button.guild.id
, it should fix the problem.
button.guild.channels.create('cs', {
type: "text",
parent_id: '802172599836213258',
permissionOverwrites: [
{
id: button.guild.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
},
{
id: button.clicker.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
}
]
})
Upvotes: 0