Skip to content

[BUG] interactions.SlashContext.expired: TypeError: can't compare offset-naive and offset-aware datetimes #1623

@Zhaxxy

Description

@Zhaxxy

Library Version

5.11.0

Describe the Bug

When i access the interactions.SlashContext.expired propety on a ctx: interactions.SlashContext object it raises an error

Lib\site-packages\interactions\models\internal\context.py", line 341, in expired
    return datetime.datetime.utcnow() > self.expires_at
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

Steps to Reproduce

simply access this propety on a ctx object

Expected Results

it should return a bool, True if its expired and False if its not

Minimal Reproducible Code

import interactions

@interactions.slash_command(name="ping",description=f"Test if the bot is responding")
async def ping_test(ctx: interactions.SlashContext):
    if ctx.expired:
        print('uh oh ive expired!')

bot = interactions.Client()
bot.start("token_here")

Traceback

Ignoring exception in cmd /ping:
Traceback (most recent call last):
File "C:\Users\Gamer\AppData\Local\Programs\Python\Python311\Lib\site-packages\interactions\client\client.py", line 1900, in __dispatch_interaction
response = await callback
^^^^^^^^^^^^^^
File "C:\Users\Gamer\AppData\Local\Programs\Python\Python311\Lib\site-packages\interactions\client\client.py", line 1771, in _run_slash_command
return await command(ctx, **ctx.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gamer\AppData\Local\Programs\Python\Python311\Lib\site-packages\interactions\models\internal\command.py", line 132, in call
await self.call_callback(self.callback, context)
File "C:\Users\Gamer\AppData\Local\Programs\Python\Python311\Lib\site-packages\interactions\models\internal\application_commands.py", line 802, in call_callback
return await self.call_with_binding(callback, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gamer\AppData\Local\Programs\Python\Python311\Lib\site-packages\interactions\models\internal\callback.py", line 43, in call_with_binding
return await callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\coding_projects\Python_projects\eZwizard3-bot\main.py", line 5, in ping_test
if ctx.expired:
^^^^^^^^^^^
File "C:\Users\Gamer\AppData\Local\Programs\Python\Python311\Lib\site-packages\interactions\models\internal\context.py", line 341, in expired
return datetime.datetime.utcnow() > self.expires_at
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.
  • I have attempted to debug this myself, and I believe this issue is with the library

Additional Information

on line 341 in interactions\models\internal\context.py, you could try replacing the line with

        return datetime.datetime.utcnow().timestamp() > self.expires_at.timestamp()

since i dont think timezone matters here (EDIT this does not work it always returns True after 3 seconds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions