简体   繁体   English

为什么在运行我的 discord.py 代码时出现错误?

[英]Why do i get an error when running my discord.py code?

I always get this error code when I run my discord.py bot.当我运行我的 discord.py 机器人时,我总是得到这个错误代码。 this is the error code:这是错误代码:

Traceback (most recent call last):
  File "C:\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
TypeError: on_ready() missing 1 required positional argument: 'self'

This is the link to my full code:这是我完整代码的链接:

https://pastebin.com/wVftj2kF https://pastebin.com/wVftj2kF

I ran my bot before changing the "on-ready" event to include 'self' and it worked.在将“on-ready”事件更改为包含“self”之前,我运行了我的机器人并且它起作用了。 Removing 'self' breaks the "self.user" part of the command.删除“self”会破坏命令的“self.user”部分。 I need help quick.我需要快速帮助。 Thanks a lot if you can help.如果您能提供帮助,非常感谢。

You don't actually need to refer to self outside of a class in order to retrieve attributes of the bot, you can just use client.您实际上不需要在 class 之外引用 self 来检索机器人的属性,您只需使用 client.

@client.event
async def on_ready():
    change_status.start()
    print('Logged on as {0}!'.format(client.user))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试运行我的机器人时,为什么会出现这个奇怪的错误? (discord.py) - Why do i get this weird error when i try to run my bot? (discord.py) 为什么我的 discord.py 代码中出现此错误 - Why i've this error in my discord.py code 为什么我的嵌入看起来像 Discord.py 上的代码? - Why do my embeds look like code on Discord.py? Discord.py 运行我的代码时出现 VSCode 错误:NameError: name 'TOKEN' is not defined - Discord.py VSCode error when running my code: NameError: name 'TOKEN' is not defined 为什么我在 discord.py 中的前缀出现此错误 - Why I've this error with my prefix in discord.py 启动我的 discord.py 机器人时出现错误 - I have a error when starting my discord.py bot 使用discord.py在python中为我的discord bot编写spotify info命令,运行命令时我没有收到任何错误 - writing a spotify info command for my discord bot in python using discord.py, I dont receive any error when running command 我的代码在 discord.py Cogs 中持续运行两次 - My code keeps running twice in discord.py Cogs 如何在我的 discord 服务器中获取消息作者的时区? (不和谐.py) - How do I get the timezone of the message author in my discord server? (discord.py) 运行发誓过滤器代码时出错 (discord.py) - Error while running swear filter code (discord.py)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM