After initially coding these functions, I encountered an unexpected behavior with .overwritePermissions()
erasing set permissions. Upon revisiting my code to address this issue, I aimed to modify joinPrivateChannel()
to utilize .updateOverwrite()
in order to avoid wiping out the channel permissions for the user creating the channel.
The function createPrivateChannel()
consistently operates without any issues, whereas the second function triggers the error
TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
. Despite attempting various approaches like hardcoding a user ID, member variable, role ID, and role variable, no solution seemed to resolve the problem. If any further details are needed, please feel free to ask. Thank you for your assistance.
async function createPrivateChannel(serverId, channelName, message) {
const guild = await client.guilds.fetch(serverId);
const everyoneRole = guild.roles.everyone;
const staffRole = guild.roles.Owner;
const channel = await guild.channels.create(channelName, 'lobby')
await channel.setParent(lobby_category);
await channel.overwritePermissions([
{type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
{type: 'role', id: everyoneRole.id, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
]);
channel.send('+start');
return;
}
async function joinPrivateChannel(serverId, channel, message){
const guild = await client.guilds.fetch(serverId);
await channel.updateOverwrite([
{type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
]);
};