some fixes, code cleanup :)

This commit is contained in:
Uwe Pfeifer 2022-05-26 21:50:10 +02:00
parent 4c15168fde
commit face2aec39

View file

@ -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())