Reputation: 309
I'm trying to make a command where it loads a certain cog I created in a "cogs" folder
I've looked through the docs & interwebs (as usual) but nothing worked for me, I might've been doing it wrong or something maybe?
The code is pretty simple but should still work
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions, MissingPermissions
import os
client = commands.Bot(command_prefix=commands.when_mentioned_or('.'))
@client.event
async def on_ready():
print ("Bot is online!")
for filename in os.listdir(f"./cogs"):
if filename.endswith(f".py"):
client.load_extension(f"cogs.{filename[:-3]}")
@client.command()
@has_permissions(administrator=True)
async def unloadchat(ctx, extension):
client.unload_extension("cogs.chat")
await ctx.send('Unloaded the "chat" module :thumbsup: ')
client.run('TOKEN')
This isn't the whole bot of course but it's what I'm trying to do, & yes I added in the token, just not making it public
Upvotes: 0
Views: 1609
Reputation: 11
You can try in different ways. Also this will be great
initial_ext = ['cogs.chat']
if __name__ == '__main__':
for extension in initial_ext:
try:
client.load_extension(extension)
except Exception as e:
print(f"Failed to load the {extensiom}", file=sys.stderr)
traceback.print_exc()
Upvotes: 1