#Unable to unload cog with BridgeCommand?

1 messages · Page 1 of 1 (latest)

neat island
#

Hi, is it possible to unload/reload a cog with BridgeCommand? Whenever I try to unload the extension, it raises "AttributeError: 'BridgeCommand' object has no attribute 'name'".

Expected: unloads/reloads the targeted cog
Result: Raises an error

Traceback

 Traceback (most recent call last):
  File "/root/bot/cogs/admin.py", line 86, in unload
    self.bot.unload_extension(cog)
  File "/usr/local/lib/python3.10/dist-packages/discord/cog.py", line 1066, in unload_extension
    self._remove_module_references(lib.__name__)
  File "/usr/local/lib/python3.10/dist-packages/discord/cog.py", line 722, in _remove_module_references
    self.remove_cog(cog_name)
  File "/usr/local/lib/python3.10/dist-packages/discord/cog.py", line 706, in remove_cog
    cog._eject(self)
  File "/usr/local/lib/python3.10/dist-packages/discord/cog.py", line 592, in _eject
    bot.remove_command(command.name)
AttributeError: 'BridgeCommand' object has no attribute 'name'```

Code
```py
@commands.command(name='reload', aliases=['rl'])  
async def reload(self, ctx, cog):
    extensions = self.bot.extensions  # A list of the bot's cogs/extensions.
    cog = "cogs." + cog
    if cog in extensions:
        try:
            # Using reload_extension does not work neither
            self.bot.unload_extension(cog)  # Unloads the cog
            self.bot.load_extension(cog)  # Loads the cog
            print(f"\n=====\nCog {cog} reloaded\n=====")
            await ctx.send(f"Cog {cog[5:]} reloaded")  # Sends a message
        except:
            await ctx.send("Stacktrace", file=discord.File(io.BytesIO(traceback.format_exc().encode("utf-8")), f"error.txt"))
    else:
        await ctx.send('Unknown Cog: ' + cog[5:])  # If the cog isn't found/loaded.```
misty plover
#

just use reload lul

#

And where is the [:-3]? Im not sure if you need that

night fog
#

Wait isn't we need to use @brideg.bridge_commands for bridge command 🤔

misty plover
#

Also you need ctx.respond and not ctx.send

night fog
misty plover
neat island
misty plover
#

Can you show the pip list?

neat island
#
------------------ ----------
aiohttp            3.8.3
aiosignal          1.3.1
async-timeout      4.0.2
attrs              22.1.0
certifi            2022.12.7
cffi               1.15.1
charset-normalizer 2.1.1
frozenlist         1.3.3
idna               3.4
mcipc              2.4.2
multidict          6.0.3
pip                22.0.2
py-cord            2.3.2
pycparser          2.21
PyNaCl             1.5.0
rcon               2.3.8
requests           2.28.1
setuptools         59.6.0
typing_extensions  4.4.0
urllib3            1.26.13
wheel              0.37.1
yarl               1.8.2
youtube-dl         2021.12.17```
misty plover
#

Can you show where you define the bot?

neat island
#
import os
from discord.ext import bridge
import discord
import json

intents = discord.Intents.all()

bot = bridge.Bot(command_prefix="-", intents=intents)

bot.author_id = 127312771888054272  # Change to your discord id!!!

@bot.event 
async def on_ready():  # When the bot is ready
    print("Bot started up")
    print(bot.user)  # Prints the bot's username and identifier
    await bot.change_presence(activity=discord.Game(name="-help | " + json.load(open(f"music_en.json","r"))["cog_name"]))

if __name__ == '__main__':  # Ensures this is the file being ran
    bot.remove_command("help")
    for extension in os.listdir("./cogs"):
        if extension[-3:] == ".py" and "_dev" not in extension: # i don't want to load some cogs so i excluded some of them
            bot.load_extension(f"cogs.{extension[:-3]}")  # Loads every extension.

token = "mytoken" 
bot.run(token)

this one?

misty plover
#

Can you remove the "name=" stuff?

#

At the bridge command

neat island
#

removed, but still raising error