问题
@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.
回答1:
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()
来源:https://stackoverflow.com/questions/59801751/discordpy-tasks-not-working-as-expected-no-returning