我正在尝试制作一个机器人,让成员在语音频道上扮演角色,但由于某种原因它不起作用。这是代码:@client.eventasync def on_voice_state_update(before, after): role = discord.utils.get(after.server.roles, name="glosowy") if not before.voice.voice_channel and after.voice.voice_channel: await client.add_roles(after, role) elif before.voice.voice_channel and not after.voice.voice_channel: await client.remove_roles(after, role)这是我收到的错误:Ignoring exception in on_voice_state_updateTraceback (most recent call last): File "C:\Users\aaa\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 312, in _run_event await coro(*args, **kwargs)TypeError: on_voice_state_update() takes 2 positional arguments but 3 were given
1 回答
米琪卡哇伊
TA贡献1998条经验 获得超6个赞
你忘记了参数'member'
从文档
async def on_voice_state_update(member, before, after)
之前和之后是 VoiceState,代表成员(在参数中)是否静音、广播等信息……
因此你不能从中检索角色你必须从成员那里得到它
@client.event
async def on_voice_state_update(member, before, after):
role = discord.utils.get(member.guild.roles, name="glosowy")
if role: # verify their is a role with that name
if not before.channel and after.channel: # check member just entered a channel
await member.add_roles(role) #add role to it
elif before.channel and not after.channel: # check member just left a channel
await member.remove_roles(role) # remove role to it
添加回答
举报
0/150
提交
取消