@tasks.loop() didn’t work.
Hello I want to write some task that fires daily about specific hour. I copy and paste example code from discord.py documentation but it didn’t work. No errors, no warnings just nothing. I set up all intents and administrator permision on my bot. Ofcourse I’ve changed time parameters to few minutes after my current time.
import datetime
from discord.ext import commands, tasks
from config import TEST_SERVER
import pytz
utc = pytz.UTC
time = datetime.time(hour=10, minute=35, tzinfo=utc)
class MyCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.my_task.start()
def cog_unload(self):
self.my_task.cancel()
@tasks.loop(time = time)
async def my_task(self):
print("My task is running!")
@commands.command()
async def test_ping(self, ctx):
await ctx.send("Test ping")
async def setup(bot:commands.Bot) -> None:
await bot.add_cog(MyCog(bot), guild=TEST_SERVER)
I’ve only added test ping command which works, setup and pytz for timezone aware.
Someone know why what’s going on?
Deathleaper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.