本文介绍了Discord.py>如何安排手术?我尝试使用时间表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试每30分钟安排一次手术.但是此代码无法正常工作.

I'm trying to schedule a operation every 30 minutes. But this code isn't working.

def Advice():
    print("30 minutes")
@client.event
async def on_ready():
    schedule.every(30).minutes.do(Advice)

你能帮我吗?

推荐答案

可能就是您想要的.这是给你的例子.

This might be what you're looking for. Here's an example for you.

class Heartbeat(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.heartbeat.start()

    def cog_unload(self):
        self.heartbeat.stop()

    @tasks.loop(seconds=45)
    async def heartbeat(self):
        if not self.bot.debug:
            try:
                self.bot.log.info("[UptimeRobot HeartBeat] - Sending heartbeat Request")
                req = await self.bot.session.get(os.getenv("UPTIMEROBOT_URL"))
                response = await req.json()
                self.bot.log.info(f"[UptimeRobot Heartbeat] - UptimeRobot says: {response['msg']}")
            except Exception as e:
                self.bot.sentry.capture_exception(e)

    @heartbeat.before_loop
    async def before_update_loop(self):
        await self.bot.wait_until_ready()


def setup(bot):
    bot.add_cog(Heartbeat(bot))

这篇关于Discord.py>如何安排手术?我尝试使用时间表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:16