[英]TypeError: on_voice_state_update() takes 2 positional arguments but 3 were given
I'm trying to make a bot that gives members a role while being on a voice channel, but for some reason it doesn't work.我正在尝试制作一个机器人,在语音频道上为成员提供角色,但由于某种原因它不起作用。
Here's the code:这是代码:
@client.event
async 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)
And here's the error I receive:这是我收到的错误:
Ignoring exception in on_voice_state_update
Traceback (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
you forgot the parameter 'member'您忘记了参数“成员”
from the documentation从文档
async def on_voice_state_update(member, before, after)
before and after are VoiceState which stand for information on if the member (in parameter) is muted, broadcasting etc... see here之前和之后是 VoiceState 代表成员(在参数中)是否静音,广播等信息......请参阅 此处
therefore you can't retrieve role from it you have to get it from the member因此您无法从中检索角色,您必须从成员那里获取它
@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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.