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()