【发布时间】:2021-09-27 15:49:41
【问题描述】:
此代码的目的是当参与者加入某个语音频道时,会创建他的个人语音频道。并且当语音通道为空时,它会被自动删除。该代码完美地执行其任务,但我在控制台中收到错误。我该如何解决这个问题?
代码:
@Bot.event
async def on_voice_state_update(member,before,after):
if after.channel.id == 826351221145206855:
for guild in Bot.guilds:
maincategory = discord.utils.get(guild.categories, id=816323445213626368)
channel2 = await guild.create_voice_channel(name=f'HALL {member.display_name}',category = maincategory)
await channel2.set_permissions(member,connect=True,mute_members=True,move_members=True,manage_channels=True)
await member.move_to(channel2)
def check(x, y, z):
return len(channel2.members) == 0
await Bot.wait_for('voice_state_update', check=check)
await channel2.delete()
控制台出错:
Ignoring exception in on_voice_state_update
Traceback (most recent call last):
File "C:\Users\Маки\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "d:\import discord.py", line 242, in on_voice_state_update
if after.channel.id == 826351221145206855:
AttributeError: 'NoneType' object has no attribute 'id'
【问题讨论】:
-
错误显示
after.channel是None。首先,您可以使用print()查看after中的内容
标签: python discord discord.py