python - 类型错误:on_ready() 缺少 1 个必需的位置参数:'self' discord.py
问题描述
我有一个不和谐的机器人,但 on_ready 总是给我一个错误:
Traceback (most recent call last):
File "/home/container/.local/lib/python3.9/site-packages/discord/client.py", line 333, in _run_event
await coro(*args, **kwargs)
TypeError: on_ready() missing 1 required positional argument: 'self'
这是我的代码
@client.event
async def on_ready():
print("Connected")
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=" for *help"))
以前可以,现在不行了,为什么?
解决方案
如果删除self
参数会发生什么?
据我所知,您仅self
在函数在类对象中定义时才输入参数。因此,宁愿删除它或将您的代码重写/扩展为类对象函数。
推荐阅读
- django - 同时拥有用户名和电子邮件,但使用电子邮件在 django-rest-auth 中对用户进行身份验证
- java - 如何告诉快速排序算法它应该终止?
- python - 如何更新/应用验证到熊猫列
- ruby-on-rails - Rails:渲染不更新页面,但它正在响应中返回
- python - 值错误:无法将字符串转换为浮点数:由于标题
- python - 计数器结束后退出循环
- google-apps-script - Google 表格 - 将单个日期变量扩展为脚本中的日期范围
- php - 使用 span 隐藏和显示内容
- ios - 用不同的数据重用 UITableViewCell
- apache-flink - 任务管理器接收消息乱序