-
I have two cogs file: 'cmds.py' and 'events.py' for filename in os.listdir("./cogs"):
if filename.endswith(".py") and filename != "__init__.py":
async def setup_hook():
await bot.load_extension(f'cogs.{filename[:-3]}')
bot.setup_hook = setup_hook the code not working is class Events(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
for guild in self.bot.guilds:
channel = guild.system_channel
if guild.id != well_thats_my_guild_id:
print("Unknown Server")
else:
print("known server")
async def setup(bot):
await bot.add_cog(Events(bot)) i think i misunderstood something about sync def setup thing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You're overwriting the To properly load multiple extensions you should only define the async def setup_hook():
for filename in os.listdir(...):
await bot.load_extension(...) |
Beta Was this translation helpful? Give feedback.
You're overwriting the
setup_hook
that you created in earlier iterations of the loop with every iteration following it, which is why it loads one of the extensions but will never work for 2 or more.To properly load multiple extensions you should only define the
setup_hook
function once and instead move the loop searching and loading extensions into it: