pycord icon indicating copy to clipboard operation
pycord copied to clipboard

AttributeError: 'SlashCommand' object has no attribute 'id'

Open krittick opened this issue 5 years ago • 5 comments

Summary

Reloading an extension containing a cog with a slash command fails with AttributeError

Reproduction Steps

  1. Create an extension file named slash-commands.py containing a cog that has the provided repro code, and add the extension to the bot via bot.load_extension()
  2. Call bot.reload_extension() on the extension (the example command below works to trigger the bug if needed)
  3. Observe the error

Example bot command to reload the extension (e.g. !reload_extension slash-commands ):

@commands.command(aliases=['reload_plugin', 'rp', 'rex'])
@commands.is_owner()
async def reload_extension(self, ctx, extension: str = None):
    """Reloads the specified extension"""
    if extension is None:
        await ctx.send("No extension specified")
    else:
        self.bot.reload_extension(settings.extensions_folder + "." + extension)
        await ctx.send("Extension " + extension + " has been successfully reloaded.")

Minimal Reproducible Code

from discord.ext import commands
from config import settings

class SlashCommands(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.slash_command(guild_ids=settings.guild_ids)
    async def saytest(self, ctx):
        await ctx.respond("test")

def setup(bot):
    bot.add_cog(SlashCommands(bot))

Expected Results

The extension should reload successfully without the AttributeError

Actual Results

Traceback (most recent call last):
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/ext/commands/core.py", line 171, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/ubuntu/cbot/extensions/admin.py", line 37, in reload_extension
    self.bot.reload_extension(settings.extensions_folder + "." + extension)
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/cog.py", line 812, in reload_extension
    self._remove_module_references(lib.__name__)
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/cog.py", line 606, in _remove_module_references
    self.remove_cog(cogname)
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/cog.py", line 590, in remove_cog
    cog._eject(self)
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/cog.py", line 476, in _eject
    bot.remove_application_command(command)
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/bot.py", line 109, in remove_application_command
    return self.application_commands.pop(command.id)
AttributeError: 'SlashCommand' object has no attribute 'id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 662, in invoke
    await ctx.command.invoke(ctx)
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/ext/commands/core.py", line 898, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/ubuntu/cbot/cbot-env/lib/python3.8/site-packages/discord/ext/commands/core.py", line 180, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'SlashCommand' object has no attribute 'id'

Intents

members, presences

System Information

- Python v3.8.0-final
- pycord v2.0.0-alpha
    - pycord pkg_resources: v2.0.0a3957+ga4e816a4
- aiohttp v3.7.4.post0
- system info: Linux 5.4.0-1029-aws #30~18.04.1-Ubuntu SMP Tue Oct 20 11:09:25 UTC 2020

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

No response

krittick avatar Sep 11 '21 21:09 krittick

Can you confirm that you were on the lastest feature/slash branch? Also I think this is a probably an issue since SlashCommand.id hasn't been implemented yet.

Grace-codes avatar Sep 12 '21 02:09 Grace-codes

Ive had this issue as well and can confirm that I was on the latest version. This error would happen before my version of issue #134

LilJess13 avatar Sep 12 '21 03:09 LilJess13

Can you confirm that you were on the lastest feature/slash branch? Also I think this is a probably an issue since SlashCommand.id hasn't been implemented yet.

Yup, I had cloned the feature/slash branch into a fresh venv about 5 minutes before encountering the error.

krittick avatar Sep 12 '21 04:09 krittick

I got the same error, found out that in my code, having same function name and command name reproduces this error. If i change either of the one, everything works fine. By function name i mean async def function_name(self, ctx) part and by command name i mean @commands.slash_command(name=command_name)

quriousprof avatar Oct 29 '21 12:10 quriousprof

This has been fixed.

CodeWithSwastik avatar Nov 05 '21 04:11 CodeWithSwastik