0
votes

I followed some tutorials and mixed some of the codes around and it works but I'm having difficulty understanding async with message.guild.channels.forEach no matter how i play to change it.

I want the bot to join only the voice channel where the user typed 'test' without running on all voice channels.

thank you

exports.run = async (client, message, args, level) => {

  async function play(channel) {
    await channel.join().then(async (connection) => {
      let dispatcher = await connection.playFile('./img/aniroze.mp3');
      await dispatcher.on('end', function () {
        message.channel.send("???? **x** ????").then(sentEmbed => {
          sentEmbed.react("????")
          sentEmbed.react("????")
        channel.leave();});
      });
  });
  }

  let timer = 10000;
       message.guild.channels.forEach(async (channel) => {
       if (channel.type == 'voice' && channel.members.size > 1) {
      const embed2 = new Discord.RichEmbed()
      .setTitle('???? ????')
      .setColor("#3498DB")
      .setThumbnail(`${message.author.displayAvatarURL}`)
      .setTimestamp()
      message.channel.send(embed2);
      setTimeout(function () {
        play(channel);
      }, timer);
    }});

  setTimeout(function () {
  }, timer);
};

exports.conf = {
  enabled: true,
  aliases: ['test'],
  guildOnly: true,
  permLevel: 'User'
}
1
You are not really clear about what your issue is. Also, please refrain from asking more than 1 question in a question. You should always write it as a separate question.Syntle
thank u for ur reply, i edited my question, there isn't issue, the bot doing what it does im just looking for an alternative from forEach that will make the bot just join the same voice channel where the user typed 'test' without running on all voice channels on the server...Bokobi

1 Answers

1
votes

If you want the bot to join the voice channel of the user that sent the command then use this:

const voiceChannel = message.member.voiceChannel

if (!voiceChannel) return message.reply('you are not in a voice channel')

voiceChannel.join()

Note: This is a discord.js v11 answer, for v12 replace member.voiceChannel with member.voice.channel