From 4c15168fdeaed92e17a3b0706dd23f5805cc1b50 Mon Sep 17 00:00:00 2001 From: Uwe Pfeifer Date: Thu, 26 May 2022 17:10:20 +0200 Subject: [PATCH] working bot but commands dont get registered on the guilds yet. --- pybot-f.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pybot-f.py b/pybot-f.py index 21990c9..8883724 100644 --- a/pybot-f.py +++ b/pybot-f.py @@ -3,6 +3,7 @@ import os import configparser import discord +import asyncio from discord.ext import commands description = '''Testing this bot stuff :)''' @@ -37,15 +38,20 @@ async def joined(ctx, member: discord.Member): """Says when a member joined.""" await ctx.send(f'{member.name} joined {discord.utils.format_dt(member.joined_at)}') -with os.scandir('./ext/') as dirs: - for entry in dirs: - if entry.name.endswith('.py'): - try: - print(entry.name) - await bot.load_extension('ext.' + entry.name) - except Exception as error: - print(f'Error loading {entry.name}: {error}') +async def scanext(): + with os.scandir('./ext/') as dirs: + for entry in dirs: + if entry.name.endswith('.py'): + try: + print(f"Loading extension: {entry.name}") + await bot.load_extension('ext.' + os.path.splitext(entry.name)[0]) + except Exception as error: + print(f'Error loading {entry.name}: {error}') -bot.load_extension('ext/test.py') -bot.run(bottoken) +async def main(): + async with bot: + await scanext() + await bot.start(bottoken) + +asyncio.run(main()) \ No newline at end of file