首页 > 解决方案 > 类型错误: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"))

以前可以,现在不行了,为什么?

标签: pythondiscord.py

解决方案


如果删除self参数会发生什么?

据我所知,您仅self在函数在类对象中定义时才输入参数。因此,宁愿删除它或将您的代码重写/扩展为类对象函数。


推荐阅读