some fixes, code cleanup :)
This commit is contained in:
parent
4c15168fde
commit
face2aec39
1 changed files with 30 additions and 4 deletions
34
pybot-f.py
34
pybot-f.py
|
@ -4,6 +4,7 @@ import os
|
||||||
import configparser
|
import configparser
|
||||||
import discord
|
import discord
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import typing
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
description = '''Testing this bot stuff :)'''
|
description = '''Testing this bot stuff :)'''
|
||||||
|
@ -17,7 +18,7 @@ config = configparser.ConfigParser()
|
||||||
config.read('bot.ini')
|
config.read('bot.ini')
|
||||||
bottoken = config['General']['bottoken']
|
bottoken = config['General']['bottoken']
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix='?', description=description, intents=intents)
|
bot = commands.Bot(command_prefix='.', description=description, intents=intents)
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
|
@ -34,9 +35,33 @@ async def repeat(ctx, times: int, content='repeating...'):
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def joined(ctx, member: discord.Member):
|
@commands.is_owner()
|
||||||
"""Says when a member joined."""
|
async def sync(ctx: commands.Context, guilds: commands.Greedy[discord.Object], spec: typing.Optional[typing.Literal["~", "*"]] = None) -> None:
|
||||||
await ctx.send(f'{member.name} joined {discord.utils.format_dt(member.joined_at)}')
|
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():
|
async def scanext():
|
||||||
with os.scandir('./ext/') as dirs:
|
with os.scandir('./ext/') as dirs:
|
||||||
|
@ -54,4 +79,5 @@ async def main():
|
||||||
await scanext()
|
await scanext()
|
||||||
await bot.start(bottoken)
|
await bot.start(bottoken)
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
Loading…
Add table
Reference in a new issue