无法同时使用discord.py和quarry

问题描述 投票:0回答:1

[我正在尝试使用discord.py制作一个discord机器人,该机器人使用库采石场与Minecraft服务器进行交互。

[不幸的是,一旦我使用bot.run()启动了Discord机器人,就无法使用Reactor.run()启动用于采石的反应堆。

我环顾四周,包括aiostream和asyncio,但找不到解决方案。当采石场使用时,我也发现扭曲了。

python-3.x async-await twisted discord.py minecraft
1个回答
0
投票

bot.run()是阻塞调用,这意味着它将停止程序执行,直到完成为止。尝试类似await bot.start()的替代方法:

import asyncio
from discord.ext import tasks

async def start_bot():
    await bot.start('my_token_goes_here')
@tasks.loop(count=1)
async def login_quarry():
    # login to quarry here #
login_quarry.start()


# put any code you need BEFORE this:
asyncio.get_event_loop().run_until_complete(start_bot())

在python 3.7及更高版本中,有一个更简单的选择:

import asyncio
from discord.ext import tasks

async def start_bot():
    await bot.start('my_token_goes_here')
@tasks.loop(count=1)
async def login_quarry():
    # login to quarry here #
login_quarry.start()


# put any code you need BEFORE this:
asyncio.run(start_bot())
© www.soinside.com 2019 - 2024. All rights reserved.