interactions-py / interactions.py

A highly extensible, easy to use, and feature complete bot framework for Discord
https://interactions-py.github.io/interactions.py/
MIT License
839 stars 184 forks source link

[BUG] AutoShardedClient with extensions errors on async-extension-loader #1687

Closed mifuyutsuki closed 4 months ago

mifuyutsuki commented 5 months ago

Library Version

unstable @ fecf3d31

Describe the Bug

Using AutoShardedClient with a loaded extension causes the application to dispatch (not crash on, fortunately) an error in async-extension-loader. For typical extensions with slash commands, this is not a big issue - commands inside the extension still load. However, in the case of the builtin jurigged extension, this issue causes the extension to fail to hot-reload the bot code. More generally, the client is unable to call extensions' async_start() methods.

Steps to Reproduce

Create and run a bot with AutoShardedClient and an extension. The MRC below uses the builtin jurigged.

The slash command is not needed to reproduce the error dispatch, but it does show the consequence of the error. In the case of using jurigged, while the bot is running, try calling the main command before and after editing the content of ctx.send().

Expected Results

Extension(s) load without errors. In the case of the jurigged extension, the bot is able to be hot-reload, for example from editing the contents of ctx.send().

Minimal Reproducible Code

from interactions import AutoShardedClient, Intents
bot = AutoShardedClient(intents=Intents.DEFAULT)

@slash_command(name="main", description="Main command")
async def main_cmd(ctx):
  await ctx.send("Sent from main")

bot.load_extension("interactions.ext.jurigged")
bot.start("token")

Traceback

Ignoring exception in async-extension-loader:
Traceback (most recent call last):
    await asyncio.gather(*self.async_startup_tasks)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\Python\Python311\Lib\asyncio\tasks.py", line 826, in gather
    if arg not in arg_to_fut:
       ^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'dict'

Checklist

Additional Information

This issue was first raised in the library Discord server in a thread: https://discord.com/channels/789032594456576001/1242911095753019422

My own investigation shows that AutoShardedClient unpacks its inherited attribute async_startup_tasks the wrong way compared to how Client does. A pull request will be made to fix this issue.