Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “如何修复”;discord.ext.commands.errors.MissingRequiredArgument:作者是缺少的必需参数。”;不和谐_Python_Discord.py Rewrite - Fatal编程技术网

Python “如何修复”;discord.ext.commands.errors.MissingRequiredArgument:作者是缺少的必需参数。”;不和谐

Python “如何修复”;discord.ext.commands.errors.MissingRequiredArgument:作者是缺少的必需参数。”;不和谐,python,discord.py-rewrite,Python,Discord.py Rewrite,我正在尝试为我的bot生成一个命令,允许用户生成bug报告,但是当我尝试运行代码时,我不断收到一个错误 @client.command() 异步定义错误(ctx、作者、消息、m): 等待ctx。发送(“问候!您想报告什么?”) 返回m.author==message.author和m.channel==message.channel msg=wait client.wait_for('message',check=bug) bugReport=msg[2:] 等待ctx.send(“感谢您的帮助

我正在尝试为我的bot生成一个命令,允许用户生成bug报告,但是当我尝试运行代码时,我不断收到一个错误

@client.command()
异步定义错误(ctx、作者、消息、m):
等待ctx。发送(“问候!您想报告什么?”)
返回m.author==message.author和m.channel==message.channel
msg=wait client.wait_for('message',check=bug)
bugReport=msg[2:]
等待ctx.send(“感谢您的帮助。此错误已报告给服务器管理员。”)
通道=客户端。获取通道(专用)
等待频道。发送(bugReport+由“+作者”报告)
程序应该在接收错误消息之前询问用户想要报告什么,然后切换到错误报告通道报告问题,但是,我得到的只是错误:

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

错误表明缺少必需的参数
作者

上述代码中有3个
author
参数:

  • 在函数
    def bug(ctx、作者、消息、m)
  • 在参数
    m.author
  • 在参数
    message.author中
  • 如果author不是None,则添加一些
    :在代码中添加
    语句,以检查
    author
    参数是否存在,如果不需要,则默认将其设置为
    None

    def bug(ctx, author=None, message, m):
        # Some code here...
        if author is not None:
            await channel.send(bugReport + " was reported by " + author)
        else:
            await channel.send(bugReport)  # without author
    
    返回后的注意事项
    声明:

    return m.author == message.author and m.channel == message.channel
    

    bug
    函数的其余部分将不会执行(无用)。

    您正在重用名称
    bug
    ,以引用命令本身和检查
    wait\u for
    。看起来您还试图在函数中定义检查,但缺少定义行

    调用命令时,您似乎希望将
    author
    message
    (和
    m
    ,无论是什么)传递给协同程序。相反,它们被捆绑到单个对象中,这是第一个参数

    下面,我修改了您的代码,以便它可以从初始调用中获取
    报告
    ,或者请求它

    @client.command()
    async def bug(ctx, *, report):
        def check(message):
            return ctx.author == message.author and ctx.channel == message.channel
    
        if not report:
            await ctx.send("Greetings! What would you like to report?")
            msg = await client.wait_for('message', check=check)
            report = msg.content[2:]  # This doesn't look right to me, will remove 2 characters
        await ctx.send("Thank you for your help. This bug has been reported to the server admins.")
        channel = client.get_channel(private)
        await channel.send(report + " was reported by " + author)
    

    我应该摆脱异步吗?因为如果我这样做,我会在下一行得到一个未知的无效语法。对不起,我还不擅长异步输入输出。您应该了解
    async
    ,以了解代码的语法。[:2]是旧功能的一部分。谢谢你指出这一点。对不起,我的代码中的所有内容都很糟糕。我是个不和谐的人。