python - 如何修复“discord.ext.commands.errors.MissingRequiredArgument:作者是缺少的必需参数。” 在不和谐.py
问题描述
我正在尝试为我的机器人创建一个允许用户提交错误报告的命令,但是当我尝试运行代码时,我不断收到错误消息。
@client.command()
async def bug(ctx, author, message, m):
await ctx.send("Greetings! What would you like to report?")
return m.author == message.author and m.channel == message.channel
msg = await client.wait_for('message', check=bug)
bugReport = msg[2:]
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(bugReport + " was reported by " + author)
该程序应该在接收错误消息之前询问用户他们想要报告什么,然后切换到错误报告频道来报告问题,但相反,我得到的只是错误:
discord.ext.commands.errors.MissingRequiredArgument: author is a required argument that is missing.
解决方案
您正在重用名称bug
来引用命令本身和检查 wait_for
. 看起来您正在尝试在函数中定义检查,但您缺少定义行。
当命令被调用时,您似乎期望author
and message
(和m
,不管是什么)被传递给协程。相反,它们被捆绑到一个Context
对象中,这是第一个参数。
下面,我修改了您的代码,以便它可以report
从初始调用中获取,或者请求它。
@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)
推荐阅读
- django - django-rest-framework 自定义视图集检索多个查找参数
- c# - 在 SQL Server 的 int 列中插入空值
- php - Prestashop HelperList 回调.. 如何制作带有 url 值的简单按钮?
- javascript - 仅当单击复选框时,组合框才有必填字段
- c - 您能否提供有关为什么存储变量值的信息,但结构的大小仍然是 0 字节?
- java - SpringAOP 介绍与 AspectJ 使用 Annotations
- php - 如何在 PHP 中以原始形式从 POSTMAN 应用程序/json 接收多个值“数组”
- kubernetes - 如何在单个 YAML 文件中创建多个角色
- javascript - 如何在 Laravel webpack.mix.js 中添加全局函数?
- wordpress - 从循环中删除“添加到购物车按钮”(Wordpress 主题:Avada)