# pybot-f by freakyy85 (freaky@freakyonline.de) import os import configparser import discord import asyncio import typing from discord.ext import commands import logging # Logging loghandler = logging.FileHandler(filename='bot.log', encoding='utf-8', mode='w') discord.utils.setup_logging(handler=loghandler) # logger = logging.getLogger('discord') # logger.setLevel(logging.INFO) # handler = logging.FileHandler(filename='bot.log', encoding='utf-8', mode='w') # handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) # logger.addHandler(handler) # The bots' description description = '''Where does this appear?''' # Intents intents = discord.Intents.default() intents.members = True intents.message_content = True # Config loading config = configparser.ConfigParser() config.read('bot.ini') bottoken = config['General']['bottoken'] # Setting up commands.Bot bot = commands.Bot(command_prefix='.', description=description, intents=intents) @bot.event async def on_ready(): print(f'pybot-f logged in as {bot.user} (ID: {bot.user.id})') print(f'Bot invite URL: {discord.utils.oauth_url(bot.user.id)}') print('------') @bot.command() async def repeat(ctx, times: int, content='repeating...'): """Repeats a message multiple times.""" for i in range(times): await ctx.send(content) @bot.command() @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.") # startup loading extensions ... async def scanext(): print("Loading extensions:") for filename in os.listdir("./ext"): if filename.endswith(".py"): await bot.load_extension(f"ext.{filename[:-3]}") print(f'Loaded: {filename}') print('\n') async def main(): async with bot: await scanext() await bot.start(bottoken) asyncio.run(main())