Repository: Pycord-Development/pycord

Issue:
py-cord loop throws an task exception when set to a fixed dst and offset-aware time
### Summary

py-cord throws an exception with offset and dst-aware times set as start time in task loop

### Reproduction Steps

1. Create a task loop with a offset and dst-aware time like:

@tasks.loop(time=datetime.time(hour=17, minute=0, second=0, tzinfo=zoneinfo.ZoneInfo("Europe/Berlin")))

2. Start the bot

3. Wait for the loop to execute and see the exception

### Minimal Reproducible Code

```python

import discord
import zoneinfo
import datetime

from discord.ext import commands, tasks

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix=('!'), intents=intents)

@tasks.loop(time=datetime.time(hour=17, minute=0, second=0, tzinfo=zoneinfo.ZoneInfo("Europe/Berlin")))
async def TestReminder():
    AdminToNotify = 248181624485838849 # change to your discorduser id
    MyDiscordUser = await bot.fetch_user(AdminToNotify)
    await MyDiscordUser.send("Test")

@bot.event
async def on_ready():



    if not TestReminder.is_running():
        TestReminder.start()


bot.run(TOKEN)
```


### Expected Results

The loop should launch at the correct dst offset-aware time.

### Actual Results

An Task Exception occurs:

Task exception was never retrieved
future: <Task finished name='Task-41' coro=<Loop._loop() done, defined at /home/discordbot/BizepsBot/bizepsbot/lib/python3.10/site-packages/discord/ext/tasks/__init__.py:152> exception=TypeError("can't compare offset-naive and offset-aware times")>
Traceback (most recent call last):
  File "/home/discordbot/BizepsBot/bizepsbot/lib/python3.10/site-packages/discord/ext/tasks/__init__.py", line 158, in _loop
    self._prepare_time_index()
  File "/home/discordbot/BizepsBot/bizepsbot/lib/python3.10/site-packages/discord/ext/tasks/__init__.py", line 616, in _prepare_time_index
    if time >= time_now:
TypeError: can't compare offset-naive and offset-aware times

### Intents

discord.Intents.default() and intents.message_content = True

### System Information

- Python v3.10.10-final
- py-cord v2.4.1-final
- aiohttp v3.8.4
- system info: Linux 5.10.103-v7l+ # 1529 SMP Tue Mar 8 12:24:00 GMT 2022

### Checklist

- [X] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.

### Additional Context

In discord.py the loop can be created with the zoneinfo without throwing an exception. 

If I change the line 587 in tasks/__init__.py to:

` if next_time > datetime.datetime.now(datetime.timezone.utc).astimezone(next_time.tzinfo).timetz()`

line 599 to:

`if next_time < next_date.astimezone(next_time.tzinfo).timetz():`

and line 610-618 to:

```
  time_now = (
            now
            if now is not MISSING
            else datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
        )
        for idx, time in enumerate(self._time):
            if time >= time_now.astimezone(time.tzinfo).timetz():
                self._time_index = idx
                break
```

the exception is no longer occuring.


Discussion:

Resolving patch:
diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py
--- a/discord/ext/tasks/__init__.py
+++ b/discord/ext/tasks/__init__.py
@@ -619,9 +619,9 @@ def _prepare_time_index(self, now: datetime.datetime = MISSING) -> None:
             now
             if now is not MISSING
             else datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
-        ).timetz()
+        )
         for idx, time in enumerate(self._time):
-            if time >= time_now:
+            if time >= time_now.astimezone(time.tzinfo).timetz():
                 self._time_index = idx
                 break
         else:


Test patch: