How can I add an array of users to the channel rights? Discord.JS v14 | NEST JS

Viewed 32

I ran into a problem. I want to add an array of users to the channel rights. Everything is fine on pure js. But as soon as I do it on nestjs (typescript), it throws an error - Type '{ id: string; allow: string[]; }' is not assignable to type 'OverwriteResolvable'.

Code:

let stagechannel = interaction.guild.channels.cache.get('1012807170393378927')
let ticketsSupportRoles = [
  "772447005297475626",
]
let supportRoles = ticketsSupportRoles.map(x => {
   return {
    id: x,
    allow: ["ViewChannel"]
   };
})
              
stagechannel.edit({
  permissionOverwrites: [
    {
       id: interaction.guild.id,
       allow: ['Connect', 'ViewChannel'],
       deny: ['MoveMembers', 'ModerateMembers', 'MuteMembers', 'ManageChannels', 'MentionEveryone']
    },
    ...supportRoles
  ],
})

Complains about - supportRoles (Type '{ id: string; allow: string[]; }' is not assignable to type 'OverwriteResolvable'.)

1 Answers

I had a similar problem for a while and my solution, which I'm not sure if it was the best, was to add the type 'Array<overwriteData>' to "supportRoles"

let supportRoles: Array<overwriteData> = ticketsSupportRoles.map(x => {
   return {
    id: x,
    allow: ["ViewChannel"]
   };
})
Related