Reputation: 49
I'm having trouble setting up a command with an optional Arg to reload my cogs. It was telling me the command didn't exist and after some modifications it was reloading all of the arguments even when I use an arg for a specific cog. Currently it's trying to reload a cog called None.
My Code:
@commands.has_role("Founder")
@bot.command()
async def reload(ctx, extension=None):
if ctx.channel.name == ("dev-testing") and {extension} == None:
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
bot.unload_extension(f'cogs.{filename[:-3]}')
bot.load_extension(f'cogs.{filename[:-3]}')
await ctx.send("All cogs have been reloaded!")
print(bcolors.WARNING + "All cogs have been reloaded!" + bcolors.ENDC)
elif ctx.channel.name == ("dev-testing") and {extension} != None:
bot.unload_extension(f'cogs.{extension}')
bot.load_extension(f'cogs.{extension}')
await ctx.send(f'{extension} has been reloaded!')
print(bcolors.WARNING + f'{extension} has been reloaded!' + bcolors.ENDC)
And this is the error I get when I don't specify an arg.
discord.ext.commands.errors.ExtensionNotLoaded: Extension 'cogs.None' has not been loaded.
I have made multiple modifications to this trying to get it to work and it's still trying to load the default value for the arg. I even tried without a default value, I tried with NULL, I tried all kinds of things but can't seem to get this working properly.
Any help would be appreciated.
Upvotes: 0
Views: 290
Reputation: 15689
Why are you comparing it like this?
if {extension} != None:
When putting it inside the curly brackets you're casting it to a set, a set is never None
, simply do:
if extension is not None:
Upvotes: 1