discord.ext.commands.errors.MissingRequiredArgument: 用户是缺少的必需参数

discord.ext.commands.errors.MissingRequiredArgument: user is a required argument that is missing

我只看到没有解决方案,但我正在尝试检查发送消息的用户的角色是否是 DJ,如果是,则 skip = True 但是我不断收到此错误消息

    async def skip(self, ctx, user: discord.Member):
        role = discord.utils.find(lambda r: r.name == 'DJ', ctx.message.guild.roles)

        if role in user.roles:
            skip = True

如果您想访问调用命令的用户,请使用 ctx.author:

    async def skip(self, ctx):
        role = discord.utils.find(lambda r: r.name == 'DJ', ctx.message.guild.roles)

        if role in ctx.author.roles:
            skip = True
async def skip(self, ctx, user: discord.Member):

此函数(带有 Bot.command 装饰器)要求用户提供 1 位置参数:user.


当你从Discord调用它时,你必须写

!skip @User#0000

而不是

!skip

因为命令需要一个强制位置参数。


由于您正在使用 user 作为消息的 author,您可以将其从参数中删除并以这种方式替换它:

async def skip(self, ctx, user: discord.Member=False):
    if (not user):
        user = ctx.author
    # Here you can use user as you did before