2022-05-26 15:30:48 +02:00
|
|
|
# pybot-f by freakyy85 (freaky@freakyonline.de)
|
|
|
|
|
2022-05-26 16:26:08 +02:00
|
|
|
import os
|
2022-05-26 15:30:48 +02:00
|
|
|
import configparser
|
|
|
|
import discord
|
2022-05-26 17:10:20 +02:00
|
|
|
import asyncio
|
2022-05-26 21:50:10 +02:00
|
|
|
import typing
|
2022-05-26 15:30:48 +02:00
|
|
|
from discord.ext import commands
|
2022-05-27 19:35:46 +02:00
|
|
|
import logging
|
|
|
|
|
2022-08-17 15:32:47 +02:00
|
|
|
# Logging
|
|
|
|
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)
|
2022-05-26 15:30:48 +02:00
|
|
|
|
2022-08-07 17:47:56 +02:00
|
|
|
# The bots' description
|
2022-05-26 15:30:48 +02:00
|
|
|
description = '''Testing this bot stuff :)'''
|
|
|
|
|
2022-08-07 17:47:56 +02:00
|
|
|
# Intents
|
2022-05-26 15:30:48 +02:00
|
|
|
intents = discord.Intents.default()
|
|
|
|
intents.members = True
|
|
|
|
intents.message_content = True
|
|
|
|
|
|
|
|
# Config loading
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read('bot.ini')
|
2022-08-07 17:47:56 +02:00
|
|
|
|
2022-05-26 15:30:48 +02:00
|
|
|
bottoken = config['General']['bottoken']
|
|
|
|
|
2022-08-07 17:47:56 +02:00
|
|
|
# Setting up commands.Bot
|
2022-08-17 15:32:47 +02:00
|
|
|
bot = commands.Bot(command_prefix='.', description=description, intents=intents)
|
2022-05-26 15:30:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
2022-05-26 23:41:17 +02:00
|
|
|
print(f'pybot-f logged in as {bot.user} (ID: {bot.user.id})')
|
2022-05-26 15:30:48 +02:00
|
|
|
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()
|
2022-05-26 21:50:10 +02:00
|
|
|
@commands.is_owner()
|
2022-09-04 16:16:15 +02:00
|
|
|
async def sync(ctx: commands.Context, guilds: commands.Greedy[discord.Object],
|
|
|
|
spec: typing.Optional[typing.Literal["~", "*"]] = None) -> None:
|
2022-05-26 21:50:10 +02:00
|
|
|
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(
|
2022-05-27 19:35:46 +02:00
|
|
|
f"Synced {len(fmt)} commands {'globally' if spec is None else 'to the current guild. :)'}"
|
2022-05-26 21:50:10 +02:00
|
|
|
)
|
|
|
|
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.")
|
|
|
|
|
2022-05-26 15:30:48 +02:00
|
|
|
|
2022-09-03 08:51:28 +02:00
|
|
|
# loading extensions ...
|
2022-05-26 17:10:20 +02:00
|
|
|
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}')
|
2022-05-26 16:26:08 +02:00
|
|
|
|
|
|
|
|
2022-05-26 17:10:20 +02:00
|
|
|
async def main():
|
|
|
|
async with bot:
|
|
|
|
await scanext()
|
|
|
|
await bot.start(bottoken)
|
|
|
|
|
2022-05-26 21:50:10 +02:00
|
|
|
|
2022-09-04 16:16:15 +02:00
|
|
|
asyncio.run(main())
|