0

I'm trying to create a command that creates a temporary voice channel that you can use and gets deleted after users leave it. Everything worked just fine until I came to the point of adding users to the channel. Normally adding one user isn't an issue, but I'm trying to make it add multiple people at the same time, so you could do !vc @user1 @user2 @user3. . . etc. This is my code:

let member = message.member
user = member.user
const allowed = message.mentions.members.first()

 message.delete()
 message.guild.createChannel(`${member.user.username}'s Room`, 'voice', [{

                    id: message.guild.id,
                    deny: ['CONNECT', 'USE_VAD']

                }]).then(channel => {

                    channel.setParent('567718414454358026')

                    channel.overwritePermissions(member, {
                        CONNECT: true,
                        USE_VAD: true,
                        PRIORITY_SPEAKER: true
                    })

                    for (const allowedMember in allowed) {
                        channel.overwritePermissions(allowedMember, {
                          CONNECT: true,
                          USE_VAD: true,
                        })
                      }

                });

let privatevc = new Discord.RichEmbed()
    .setDescription(':white_check_mark: Successfully created a :lock: **private** voice channel!')
    .setColor(config.green)

await message.channel.send({ embed: privatevc }).then(msg => msg.delete(10000));

The for (const allowedMember in allowed) is the part I'm stuck on and can't get it to work to loop for every member mentioneded.

Therefore, I'd really appreciate any help possible. Thank you in advance. :)

Silent Watcher
  • 125
  • 2
  • 2
  • 9
  • Have you tried "for of" instead of "for in"? You can find the differences in this answer: [https://stackoverflow.com/a/50015996/7514874](https://stackoverflow.com/a/50015996/7514874) – Ana Lava Jun 14 '20 at 10:16
  • Just tried and now received this error: TypeError: allowed is not iterable – Silent Watcher Jun 14 '20 at 13:30
  • Why did you used `message.mentions.members.first()` ? shoudn't it be `message.mentions.members` ? – Ana Lava Jun 14 '20 at 13:37
  • Cause I was having issues with it too. I did `message.mentions.members` now and got **TypeError: Supplied parameter was neither a User nor a Role.** – Silent Watcher Jun 14 '20 at 14:22

1 Answers1

1

You would have to loop over message.mentions.members

const allowed = message.mentions.members;
allowed.each(allowedMember => {
  channel.overwritePermissions(allowedMember, {
       CONNECT: true,
       USE_VAD: true,
  });
});

You should prob instead just give them a role and change overwrites for that role.

  • Now I get `TypeError: allowed.each is not a function` hmm. – Silent Watcher Jun 14 '20 at 19:46
  • 1
    Oh you are on v11, use `allowed.forEach` instead. –  Jun 14 '20 at 19:59
  • I should have stated that hah, sorry. I didn't have time to update to 12 yet and it would mean I'd have to rewrite like half of my commands so. But it worked! Thank you so much for your help <3 – Silent Watcher Jun 14 '20 at 20:32
  • No problem, updating v12 is very worth it imo, its a lot more organized with the Manager classes/ –  Jun 14 '20 at 20:35
  • My friend (who has much more experience in bot development, I'm literally a self-learner from youtube and reading docs hah) also told me that I should update to 12 asap. So it's on top of my priority list. – Silent Watcher Jun 14 '20 at 20:38