Python discord.ext在正确通道中发送和设置状态时出现问题
我正在使用discord.py,然后使用discord.ext模块。我有一个相当长的selenium代码在Python discord.ext在正确通道中发送和设置状态时出现问题,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,我正在使用discord.py,然后使用discord.ext模块。我有一个相当长的selenium代码在while True循环中运行。这是其中的一部分: @bot.command() async def start(ctx): driver.install_addon(r'some_extension.xpi') channel = bot.get_channel(791352165393498203) user = bot.get_u
while True
循环中运行。这是其中的一部分:
@bot.command()
async def start(ctx):
driver.install_addon(r'some_extension.xpi')
channel = bot.get_channel(791352165393498203)
user = bot.get_user(257428782233812993)
while True:
await bot.change_presence(status=Status.online)
driver.get('some_link')
driver.maximize_window()
time.sleep(5)
try:
driver.find_element_by_xpath('//*[@id="pageSize"]').click()
except NoSuchElementException:
await ctx.channel.send(f" We had an Exception, please go check")
time.sleep(60)
driver.refresh()
time.sleep(5)
driver.find_element_by_xpath('//*[@id="pageSize"]').click()
time.sleep(1)
await ctx.channel.send(f"Problem solved")
这段代码的大部分工作正常,但有两个主要问题,我没有得到一个例外
- 首先,
应该在我上面提到的频道中发送,但是 没有等待ctx.channel.send(f“我们有一个异常,请检查”)
表示从未使用通道变量, 不应该是这样的pycharm
- 其次,
不会保留bot 永久显示为联机等待bot.change_presence(status=status.online)
channel.send()
而不使用ctx
,ctx
是有关所用命令(作者、频道等)的一组信息哦,我建议使用
asyncio.sleep()
而不是time.sleep()
,因为当你使用time.sleep()
时,机器人会在这段时间停止工作,并且不会响应任何命令/事件。我也读过关于ansyncio的文章,如果你说它会响应其他命令,我可以试试。实际上,我需要改变我的状态,因为机器人像24/7一样运行,只有一个启动命令,几分钟后它就离线了。我将尝试channel.send(),但在更改时间后,这对meAlright来说似乎没有什么意义。sleep by asyncio.sleep联机状态正常,channel.send而不是ctx.channel.send也正常工作。谢谢