python-3.x - Discord.py> 如何安排一个操作?我尝试使用时间表
问题描述
我正在尝试每 30 分钟安排一次手术。但是这段代码不起作用。
def Advice():
print("30 minutes")
@client.event
async def on_ready():
schedule.every(30).minutes.do(Advice)
你能帮我么?
解决方案
这可能是您正在寻找的。这是给你的一个例子。
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))
推荐阅读
- php - 使用 PHP 循环遍历 JSON
- arrays - 将值推入多维数组时出现 TSLint 接口错误
- javascript - 运行 .js 文件的 CronJob 不会将控制台输出到 .txt 或 .log 文件
- c# - 数据网格视图上未显示任何数据
- python - 想要使用经过预训练的 ResNet50 但出现错误“ValueError: Shapes (None, None) and (None, 7, 7, 3) are incompatible”
- css - 如何覆盖 CSS 默认主题 CSS WordPress
- firebase - 检索存储在 Firebase 存储中的图像
- json - 如何在codeigniter中的php中发送json对象值?
- python - scikit-learn 中的 StratifiedKFold 与 KFold
- flutter - 无法加载资产:/data/user/0/com.example.app/app_flutter/localization/en-IN.json 直到热重新加载