Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行Discord Bot(Python)时未调用on_ready_Python_Discord.py - Fatal编程技术网

运行Discord Bot(Python)时未调用on_ready

运行Discord Bot(Python)时未调用on_ready,python,discord.py,Python,Discord.py,我一直在用Python编写我的第一个Discord机器人,它工作得很好。我决定将代码重构为两个模块,而不是一个模块。看起来是这样的: Proj - src -- __init_.py -- eve.py -- event.py import discord from discord.ext import commands from discord.ext.commands import Bot import asyncio from src.event import eventCall bo

我一直在用Python编写我的第一个Discord机器人,它工作得很好。我决定将代码重构为两个模块,而不是一个模块。看起来是这样的:

Proj
- src
-- __init_.py
-- eve.py
-- event.py
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
from src.event import eventCall

bot = commands.Bot(command_prefix="!")

@bot.event
async def on_ready():
    print ("Booting up your system")
    print ("I am running on " + bot.user.name)
    print ("With the ID: " + bot.user.id)

@bot.command(pass_context=True)
async def event(ctx):
    await eventCall(ctx)

bot.run(<client ID>)
我的eve.py如下所示:

Proj
- src
-- __init_.py
-- eve.py
-- event.py
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
from src.event import eventCall

bot = commands.Bot(command_prefix="!")

@bot.event
async def on_ready():
    print ("Booting up your system")
    print ("I am running on " + bot.user.name)
    print ("With the ID: " + bot.user.id)

@bot.command(pass_context=True)
async def event(ctx):
    await eventCall(ctx)

bot.run(<client ID>)
我正努力让eve.py导入event.py,所以我将所有内容都移到了src文件夹中,这样我就不会再出现编译器错误了

但是现在,当我运行eve.py时,on_ready不再触发(我在控制台中看不到任何文本),并且!事件命令在Discord中不起作用

我认为我的文件夹结构和使用导入的语法都可能是错误的,但我不确定如何最好地解决这个问题

您必须在eve.py的on_ready函数中键入“wait print”。

请考虑阅读以下内容:

TL;博士 作为API关于意图更改的一部分,Discord还更改了成员在开始时的加载方式。最初,图书馆可以一次请求75个公会,并且只请求将Guild.large属性设置为True的公会成员。随着新意图的改变,Discord要求我们每个请求只能发送1个帮会。这导致了75倍的减速,而所有公会(而不仅仅是大型公会)都被要求加入,这进一步加剧了这一事实


有关解决方案,请访问上面的链接

注释掉src.event import eventCall行中的
(可能还有引用
eventCall
的所有行)。但是,如果找不到模块,您应该会看到异常。在
src.event
中执行的代码是否不在函数中?它将在导入文件时运行,因此可能有一个循环需要很长时间?这很有效!在event.py中有很多def,但是当它全部在一个模块中时,没有什么是不存在的。我更新了上面的帖子以显示其中的所有内容。如果
eve.py
event.py
在同一个目录中,那么您不应该使用
从event import eventCall导入它吗?每当我这样做时,Eclipse似乎都不喜欢它。我也尝试过.event,但这并没有给我一个Eclipse错误,但我最终得到一个:ModuleNotFoundError:没有名为'main.event'的模块;'“main”实际上不是一个包,它不是这样工作的。如果要调用
async
coroutine,只需使用
wait
。否则,您可以正常使用所有函数。这并不能回答问题。一旦你有足够的钱,你将能够;相反他们建议关闭分块,但我似乎无法让它工作,即使我从文档中复制代码,有什么建议吗