@bot.event
async def on_voice_state_update(member, before, after):
if before.channel is None and after.channel is not None:
print("Участник присоединился к голосовому каналу")
embed = disnake.Embed(title="Участник присоединился к голосовому каналу", color=0x00ff00)
embed.add_field(name="Участник", value=member.mention)
embed.add_field(name="ID участника", value=member.id)
embed.add_field(name="Канал", value=after.channel.mention)
embed.add_field(name="ID канала", value=after.channel.id)
await disnake.utils.get(member.guild.text_channels, id=1240402311147290685).send(embed=embed)
elif before.channel is not None and after.channel is None:
join_time = member.voice.joined_at.astimezone(moscow_tz).strftime('%Y-%m-%d %H:%M:%S')
leave_time = datetime.now(tz=moscow_tz).strftime('%Y-%m-%d %H:%M:%S')
join_time_dt = datetime.strptime(join_time, '%Y-%m-%d %H:%M:%S').replace(tzinfo=moscow_tz)
leave_time_dt = datetime.strptime(leave_time, '%Y-%m-%d %H:%M:%S').replace(tzinfo=moscow_tz)
duration = leave_time_dt - join_time_dt
hours_on = duration.seconds // 3600
minutes_on = (duration.seconds // 60) % 60
seconds_on = duration.seconds % 60
embed = disnake.Embed(title="Участник отключился от голосового канала", color=0xFF0000)
embed.add_field(name="Участник", value=member.mention)
embed.add_field(name="Канал", value=before.channel.mention)
embed.add_field(name="ID канала", value=before.channel.id)
embed.add_field(name="Время в канале", value=f'{hours_on} часов, {minutes_on} минут, {seconds_on} секунд')
await disnake.utils.get(member.guild.text_channels, id=1240402311147290685).send(embed=embed)
As I understand it, this is the problem join_time = member.voice.joined_at.astimezone(moscow_tz).strftime(‘%Y-%m-%d %H:%M:%S’)
The error itself:
Ignoring exception in on_voice_state_update
Traceback (most recent call last):
File "C:UsersfilatAppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagesdisnakeclient.py", line 703, in _run_event
await coro(*args, **kwargs)
File "C:UsersfilatDesktopvcbotmain1.py", line 245, in on_voice_state_update
join_time = member.voice.joined_at.astimezone(moscow_tz).strftime('%Y-%m-%d %H:%M:%S')
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'joined_at
Even if you add similar checks to the second part of the code, it will not help
if before.channel.members:
New contributor
LoL Cheat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.