【发布时间】:2022-01-14 18:37:42
【问题描述】:
我创建了一个 Python Discord Bot,我将所有函数放入一个类中,但是当我这样做时,我开始收到类型错误,唯一的问题是错误告诉我完全按照我的做法去做。 这是受影响的代码和错误。
client = commands.Bot(command_prefix='--', case_insensitive=True)
class Settings:
def __init__(self):
self.spitfirerole = 917086768736649258
with open("data.json") as f:
data = json.load(f)
f.close()
self.prev = data["serial"]
@client.event
async def on_ready(self):
print('ThatOneGuy is online.')
await client.change_presence(activity=discord.Game(name="chess with Mr.Z"))
channel = client.get_channel(918300328267497502)
em = discord.Embed(title=f"Status", color=0x22ff12)
em.add_field(name="Active", value=f"I am now searching for a Spitfire.")
await channel.send(f"<@&{self.spitfirerole}>", embed=em)
错误;
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\Libra\PycharmProjects\ThatOneGuy\venv\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_ready() missing 1 required positional argument: 'self'
【问题讨论】:
-
看例子。 on_ready() 方法不需要参数discordpy.readthedocs.io/en/stable/quickstart.html
-
我应该澄清一下,还有更多代码使用
self参数。所以如果我删除它,我会得到更多的错误。 -
我认为您需要以 pydiscord 事件方法尊重文档中定义的参数的方式单独编写代码
标签: python class discord.py typeerror