Discordpy任务无法按预期方式工作.没有回头 [英] Discordpy Tasks not working as expected. No returning

查看:35
本文介绍了Discordpy任务无法按预期方式工作.没有回头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@tasks.loop(seconds = 5.0)
async def remind420(self):
    print("YES")
    print(datetime.now().strftime("%H:%M"))
    if datetime.now().strftime("%H:%M") == "16:55" or datetime.now().strftime("%H:%M") == "04:20":
        await client.get_channel(499245707081940995).send("420!!")

@remind420.before_loop
async def remind420_before():
    await client.wait_until_ready()

remind420.start()

没有输出.绝对没有输出.我希望时间可以返回,或者至少可以.

There is no output. Absolutely no output. I expect the time to returned or atleast a yes.

推荐答案

请确保在before_loop函数参数中包含所有导入内容和self.如果它在齿轮内,请确保在客户之前包括self.在前一点加上小时,分钟和计数+自我似乎可以解决问题.

Make sure to have all your imports and self in the before_loop function parameters. If it is inside a cog, make sure to include self before the client. Adding the hours, minutes and count + the self in the before bit seemed to fix the issue.

import discord
from discord.ext import commands, tasks
from datetime import date, datetime

class StackOverflow(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.remind420.start()

    @tasks.loop(seconds = 5.0, minutes=0, hours=0 count=None)
    async def remind420(self):
        print("YES")
        print(datetime.now().strftime("%H:%M"))
        if datetime.now().strftime("%H:%M") == "16:55" or datetime.now().strftime("%H:%M") == "04:20":
            await self.client.get_channel(632933507399942164).send("420!!")


    @remind420.before_loop
    async def remind420_before(self):
        await self.client.wait_until_ready()

这篇关于Discordpy任务无法按预期方式工作.没有回头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆