Open
Description
Summary
Commands don't get removed from the internal cache on extension unloading.
Reproduction Steps
- Make a normal Bot.
- Make a Cog loader (like I did shown below as the for filename loop.)
- When the bot is running, try the
/ping
command --> everything works fine. - Now execute the
/unload utility
command. - Try the
/ping
command. - 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.
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.