From face2aec39ae057b6785c4c1e92c72abff47fe58 Mon Sep 17 00:00:00 2001 From: Uwe Pfeifer Date: Thu, 26 May 2022 21:50:10 +0200 Subject: [PATCH] some fixes, code cleanup :) --- pybot-f.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/pybot-f.py b/pybot-f.py index 8883724..06fce2e 100644 --- a/pybot-f.py +++ b/pybot-f.py @@ -4,6 +4,7 @@ import os import configparser import discord import asyncio +import typing from discord.ext import commands description = '''Testing this bot stuff :)''' @@ -17,7 +18,7 @@ config = configparser.ConfigParser() config.read('bot.ini') bottoken = config['General']['bottoken'] -bot = commands.Bot(command_prefix='?', description=description, intents=intents) +bot = commands.Bot(command_prefix='.', description=description, intents=intents) @bot.event @@ -34,9 +35,33 @@ async def repeat(ctx, times: int, content='repeating...'): @bot.command() -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)}') +@commands.is_owner() +async def sync(ctx: commands.Context, guilds: commands.Greedy[discord.Object], spec: typing.Optional[typing.Literal["~", "*"]] = None) -> None: + if not guilds: + if spec == "~": + fmt = await ctx.bot.tree.sync(guild=ctx.guild) + elif spec == "*": + ctx.bot.tree.copy_global_to(guild=ctx.guild) + fmt = await ctx.bot.tree.sync(guild=ctx.guild) + else: + fmt = await ctx.bot.tree.sync() + + await ctx.send( + f"Synced {len(fmt)} commands {'globally' if spec is None else 'to the current guild.'}" + ) + return + + fmt = 0 + for guild in guilds: + try: + await ctx.bot.tree.sync(guild=guild) + except discord.HTTPException: + pass + else: + fmt += 1 + + await ctx.send(f"Synced the tree to {fmt}/{len(guilds)} guilds.") + async def scanext(): with os.scandir('./ext/') as dirs: @@ -54,4 +79,5 @@ async def main(): await scanext() await bot.start(bottoken) + asyncio.run(main()) \ No newline at end of file