import discord
from discord.ext import commands
import datetime

intents = discord.Intents.default()
intents.voice_states = True

bot = commands.Bot(command_prefix="!", intents=intents)

@bot.event
async def on_ready():
    print(f'Bot conectado como {bot.user}')

@bot.event
async def on_voice_state_update(member, before, after):
    time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    
    if before.channel is None and after.channel is not None:
        print(f"{time} - {member} se conectó a {after.channel.name}")
    elif before.channel is not None and after.channel is None:
        print(f"{time} - {member} se desconectó de {before.channel.name}")
    elif before.channel != after.channel:
        print(f"{time} - {member} cambió de {before.channel.name} a {after.channel.name}")

bot.run("MTM0MjQ3NTMwOTM3MDU3NjkxOQ.GoZO8G.Bz2PA33dREmZ61CVP96eiFYMgMStvsxuA7D_ek")
