You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.py等级系统报MissingRequiredArgument: ctx参数缺失问题求助

报错原因排查与解决方案

根因

你在Cog类内部定义指令时误用了@bot.command()装饰器,Cog类内的指令必须使用@commands.command()装饰器。
@bot.command()是全局指令装饰器,作用在类方法上时,discord.py不会自动将类实例的self作为第一个参数注入,会出现参数错位:方法定义的第一个参数self被框架识别为需要传入的ctx参数,运行时缺少对应参数就会抛出ctx is a required argument that is missing的错误。

修复方法

将代码中level方法的装饰器替换即可:

- @bot.command(brief="Displays the user's level and experience.")
+ @commands.command(brief="Displays the user's level and experience.")

可选注意事项

  • 确认__init__方法前后为双下划线,避免类初始化异常:def __init__(self, client):
  • 确认头部已导入对应模块:from discord.ext import commands

内容的提问来源于stack exchange,提问作者Vanya Briggs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 20:45:03