如何修复错误"discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is mi



我正在做一个命令,当他们将?getroles输入到不和谐的bot时,将角色应用于成员。
它说所需的参数,member丢失了,但我已经把它放在我的代码中。

@client.command()
async def getoroles(ctx,member):
grabtherole = discord.utils.get(member.server.roles, name="test")
await client.add_roles(member,grabtherole)
await ctx.send(f'{ctx.author.display_name} get {grabtherole}')

但是当我运行这个命令时显示错误(发送?getroles不一致)

Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 855, in invoke
await self.prepare(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 789, in prepare
await self._parse_arguments(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 697, in _parse_arguments
transformed = await self.transform(ctx, param)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 542, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is missing.

我可以知道如何修理它吗?
我是一个做不和谐的初学者,我将感谢任何帮助。

你可以得到这样的角色:

@client.command()
async def getrole(ctx)
role = discord.utils.get(ctx.guild.role, name="your_role_name")
await ctx.author.add_roles(role)
await ctx.send(f"{role} was added to {ctx.author.display_name}!!")

如果你想在命令中添加一个可选的参数。你确实喜欢这样。

async def getrole(ctx, arg=None)

添加None作为默认值

discord.ext.commands.errors.MissingRequiredArgument表示您没有提供参数member。你应该运行?getrole <mention>而不仅仅是?getrole

相关内容