我当前正在尝试使用discord.py发出命令以重置服务器上的所有用户昵称(!!! mreset)。但是我遇到类型错误,告诉我给出了4个参数。
代码:
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!!!mreset'):
serverid = message.server.id
x = message.server.members
for member in x:
await client.change_nickname(serverid, member.name, None)
错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Saber\PycharmProjects\my_bot\venv\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Saber/PycharmProjects/my_bot/my_bot.py", line 32, in on_message
await client.change_nickname(serverid, member.name, None)
TypeError: change_nickname() takes 3 positional arguments but 4 were given
答案 0 :(得分:0)
您不需要将serverid
或Server
对象传递给change_nickname
。 Member
对象具有与之关联的服务器,因此该命令可以从Server
对象中获取适当的Member
。您还应该传递一个Member
对象,而不是Member.name
属性。
if message.content.startswith('!!!mreset'):
for member in message.server.members:
await client.change_nickname(member, None)