const { joinVoiceChannel } = require('@discordjs/voice');
const config = require('../config.js');

module.exports = {
  name: 'ready',
  once: true,
  async execute(client) {
      
    for (const guildId in config) {
      const serverConfig = config[guildId];

      if (!serverConfig.voiceChannelId) continue;

      const voiceChannel = client.channels.cache.get(serverConfig.voiceChannelId);
      if (!voiceChannel) {
        console.log(`❌ لم يتم العثور على الروم الصوتي: ${serverConfig.voiceChannelId}`);
        continue;
      }

      try {
        joinVoiceChannel({
          channelId: serverConfig.voiceChannelId,
          guildId: guildId,
          adapterCreator: voiceChannel.guild.voiceAdapterCreator,
        });
        console.log(`🤖 Bot joined voice channel: ${voiceChannel.name}`);
      } catch (err) {
        console.log(`❌ Failed to join VC: ${err.message}`);
      }
    }
  },
};
