Discordpy Tasks Not Working As Expected. No Returning
@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.no
Solution 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
classStackOverflow(commands.Cog):
def__init__(self, client):
self.client = client
self.remind420.start()
@tasks.loop(seconds = 5.0, minutes=0, hours=0 count=None)asyncdefremind420(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_loopasyncdefremind420_before(self):
await self.client.wait_until_ready()
Solution 2:
You are missing the .start()
method in on_ready()
event listener.
@bot.eventasync def on_ready():
ifnot remind420.is_running():
remind420.start()
Post a Comment for "Discordpy Tasks Not Working As Expected. No Returning"