Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension Unloading does not stop slash_commands from functioning. #2015

Open
3 tasks done
Vox314 opened this issue Apr 14, 2023 · 3 comments
Open
3 tasks done

Extension Unloading does not stop slash_commands from functioning. #2015

Vox314 opened this issue Apr 14, 2023 · 3 comments
Labels
bug Something isn't working ext.bridge Relating to ext.bridge help wanted Extra attention is needed on hold priority: high High Priority status: todo This issue needs work

Comments

@Vox314
Copy link

Vox314 commented Apr 14, 2023

Summary

Commands don't get removed from the internal cache on extension unloading.

Reproduction Steps

  1. Make a normal Bot.
  2. Make a Cog loader (like I did shown below as the for filename loop.)
  3. When the bot is running, try the /ping command --> everything works fine.
  4. Now execute the /unload utility command.
  5. Try the /ping command.
  6. It still works and does not respond with "unknown interaction" or any error defined before.

Minimal Reproducible Code

# utility.py cog
import discord

class utility(discord.Cog, name = 'utility', description = "Bot utility commands."):
    def __init__(self, bot):
        self.bot = bot

    @discord.slash_command(name = 'ping', description = f"Displays the bot latency.")
    async def ping(self, ctx): 
        await ctx.respond(f'**Pong!**\n``{round(self.bot.latency * 1000)}ms``')

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

# main.py
import discord, os
from dotenv import load_dotenv

debug_server = ID

load_dotenv()
intents = discord.Intents.default() # These are all the Intents of my actual Bot.
intents.message_content = True # Makes sure the bot can read messages
intents.members = True
bot = discord.Bot(intents = intents, auto_sync_commands = True, debug_guilds = debug_server)
colorama.init(autoreset=True)

@bot.slash_command(name = "unload", description = "Unloads a category.")
async def unload(ctx, category: Option(str, required = True)):
    try:
        bot.unload_extension(f'cogs.{category}')
        print(colorama.Fore.RED + f'Unloaded : {category}')
        await ctx.respond(f':white_check_mark:  **Unloaded {category}!**  :white_check_mark:')
    except:
        em = discord.Embed()
        em.title = ('Invalid category!')
        em.description = (f'This category does not exist or has already been unloaded.')
        em.color = 0xe74c3c
        await ctx.respond(embed = em)

for filename in os.listdir('./cogs'): # Loads all files (*.py)
    if filename.endswith('.py'):
        bot.load_extension(f'cogs.{filename[:-3]}') # Loads the file without ".py" for example: cogs.fun
        print(colorama.Fore.BLUE + f'Loaded : {filename[:-3]}')

if __name__ == '__main__':
    bot.run(os.getenv('token'))

Expected Results

The bot should have responded with "The application did not respond",
because it could not find the /ping command in the internal cache.

image

Actual Results

On unloading the Cog which contains the /ping command, it still works fine.
"still works fine" as in the /ping command still responds with the normal (not unloaded) response.

Intents

intents = discord.Intents.default(message_content=True, members=True)

System Information

  • Python v3.10.0-final
  • py-cord v2.4.1-final
  • aiohttp v3.8.4
  • system info: Windows 10 10.0.22621

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.

Additional Context

I just want to note that this is a known issue already, but it wasn't listed on GitHub as an issue and @JustaSqu1d allowed me to make an issue post here.

image

image

@Vox314 Vox314 added the unconfirmed bug A bug report that needs triaging label Apr 14, 2023
@JustaSqu1d JustaSqu1d added bug Something isn't working help wanted Extra attention is needed priority: high High Priority status: todo This issue needs work ext.bridge Relating to ext.bridge python and removed unconfirmed bug A bug report that needs triaging labels Apr 14, 2023
@Kusarigama90
Copy link

Has someone started looking at this yet? Or have an solution that can be done temporary, so I can use the unloading

@Lulalaby Lulalaby added priority: low Low Priority and removed priority: high High Priority labels Jun 21, 2023
@Vox314
Copy link
Author

Vox314 commented Jun 21, 2023

Nope, there are a lot of other Issues with this library which have to be fixed before this one too... so it's just waiting I guess.
I don't have any solution to this yet, also this can take a very very very long time as I stated before.

@Kusarigama90
Copy link

Nope, there are a lot of other Issues with this library which have to be fixed before this one too... so it's just waiting I guess. I don't have any solution to this yet, also this can take a very very very long time as I stated before.

Alright thanks for the reply, because I've even tried the await sync_commands but apparently it still wont sync like in discord.py. Would rather not convert as it feels more complicated when im new

@Dorukyum Dorukyum added priority: high High Priority and removed on hold priority: low Low Priority python labels Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ext.bridge Relating to ext.bridge help wanted Extra attention is needed on hold priority: high High Priority status: todo This issue needs work
Projects
None yet
Development

No branches or pull requests

5 participants