更改昵称Discord.py时出现问题

时间:2020-09-08 10:18:14

标签: python discord.py

我想编写一个更改特定用户昵称的命令,我编写了以下代码:

async def chnick(ctx, member: discord.Member, nick):
    await member.edit(nick="test")
    await ctx.send(f'Nickname was changed for {member.mention} ')

python抛出此错误:

Ignoring exception in command chnick:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 847, in invoke
    await self.prepare(ctx)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 784, in prepare
    await self._parse_arguments(ctx)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 690, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 535, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is missing.

请帮帮我!

1 个答案:

答案 0 :(得分:0)

您没有指定要编辑的成员。另外,您还应该将nick参数传递给member.edit()。您的命令应如下所示:!chnick @member john

@client.command()
async def chnick(ctx, member: discord.Member, *, nick):
    await member.edit(nick=nick)
    await ctx.send(f'Nickname was changed for {member.mention} ')