#Better way to write permission overwrites

1 messages · Page 1 of 1 (latest)

mild swallow
#
await channel.permissionOverwrites.set([
    ...(await tempDb.club_roles).map(id => ({ id, allow: ['VIEW_CHANNEL'] })),
    ...channel.permissionOverwrites.cache.map(po => {
        let allow = po.allow.toArray(), deny = po.deny.toArray();
        if (tempDb.club_roles.includes(po.id)) {
            if (deny.includes('VIEW_CHANNEL')) {
                deny.splice(deny.indexOf('VIEW_CHANNEL'), 1);
                po.deny = new Discord.Permissions(deny);
            }
            if (!allow.includes('VIEW_CHANNEL')) {
                allow.push('VIEW_CHANNEL');
                po.allow = new Discord.Permissions(allow);
            }
        }
        return po;
    })
]);

Is there a better way to write this while it keeps on:

  1. creating the club roles (array["123", "123"]) as overwrites when they are not yet overwrites in the channel
  2. only update the VIEW_CHANNEL overwrite, for multiple roles in the channel.
  3. all other roles and perms other than VIEW_CHANNEL for the selected roles, stay untouched?
#

I could just use a for loop and use channel.permissionOverwrites.create but that would be API spam

visual trellis
#
<interaction>.channel.edit({
    name: `name`,
    parentID: "chategory id (optional)",
    permissionOverwrites: [
            {
                 id: "id",
                  deny: ["VIEW_CHANNEL"]
            }
        ]
  })```
mild swallow
visual trellis
#

why you even want to do that

mild swallow
#

Timed events for 4 roles to see a channel

#

so @ everyone should never have view_channel perms

#

it should be denied in that channel I mean

visual trellis
#

just use { id: interacion.guild.roles.everyone, deny: ["VIEW_CHANNEL"] }

#

in each

mild swallow
#

Alright and the bot is global so I need to handle more roles being in the overwrites

visual trellis
#

cache.forEach guild?

visual trellis
#

you can go that for each guild (function) and then deny

mild swallow
#

I mean like

mild swallow
#

and I dont want to delete those every time my timed function updates the view_channel perms

visual trellis
#

they wont delete

mild swallow
#

they do sadly

visual trellis
mild swallow
#

if someone has a mute role for example in a channel

#

when I execute

<interaction>.channel.edit({
    name: `name`,
    parentID: "chategory id (optional)",
    permissionOverwrites: [
            {
                 id: interaction.guild.roles.everyone,
                 deny: ["VIEW_CHANNEL"]
            },
            {
                 id: "987",
                 deny: ["VIEW_CHANNEL"]
            },
            {
                 id: "123",
                 deny: ["VIEW_CHANNEL"]
            }
        ]
  })
visual trellis
#

how did you try that

mild swallow
#

This is a .set api request even tho you are editing the channel

visual trellis
#

so you know 100%

mild swallow
#

and set overwrites the whole channel

mild swallow
visual trellis
#

dunno then

mild swallow
#

thats why I had to first get all overwrites in a channel

#

and then edit the ones I want