I would like to create a channel with specific permissions for @everyone and a created role. So I defined the role as " rolee " and the @everyone at " everyoneRole ", I would like @everyone not to have permission to see the room, and the rolee created before to have permission to see, talk, log in and talk in the room (category type room, but permission is the same).
My code will surely be more concrete: by the way, discord.js is a bit tricky because it only accepts the code if everything is perfectly aligned, which in itself is not a problem, but is when the script doesn't work because of a single misplaced space.
let everyoneRole = message.guild.roles.cache.find(role => role.name === '@everyone');
let rolee = message.guild.roles.cache.find(role => role.name === rolename);
let crole = (
message.guild.roles.create({
data: {
name: rolename,
color: '3498DB',
},
});
);
let cat = (
message.guild.channels.create(category, {
type: "category",
position: 999,
permissionOverwrites: [
{
id: everyoneRole.id,
deny: [
'VIEW_CHANNEL',
'SEND_MESSAGES',
],
},
]
});
);
And here is the error message.
My problem is that it refuses to add multiple permission to a single role (allow : ['VIEW_CHANNEL', 'SEND_MESSAGES']).
Note: This answer is for Discord.js v13.3.0
The TypeError is occurring because when you're getting the role from the list of roles, @everyone is technically not a role. While it is a role, you can't get it by requesting it from the role cache.
// When you try to get it from this, Discord.js returns null
let everyoneRole = message.guild.roles.cache.find(role => role.name === '@everyone');
This means that you're handing Discord an empty ID which then causes the issue. The proper way to get the role for everyone, as pointed out by Niet the Dark Absol, is to use <Guild>.roles.cache.everyone (Replace <Guild> with whatever your Guild variable is). Here's what that would look like.
let everyoneRole = message.guild.roles.cache.everyone