-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
64 lines (46 loc) · 1.92 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import discord
from discord.ext import commands
from discord import app_commands
from dotenv import load_dotenv
import os
from src.log import setup_logger
from configs.load_configs import configs
log = setup_logger(__name__)
load_dotenv()
bot = commands.Bot(command_prefix=configs['prefix'], intents=discord.Intents.all())
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=configs['activity_name']))
bot.tree.on_error = on_tree_error
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.load_extension(f'cogs.{filename[:-3]}')
log.info(f'{bot.user} is online')
slash = await bot.tree.sync()
log.info(f'synced {len(slash)} slash commands')
@bot.command()
@commands.is_owner()
async def load(ctx, extension):
await bot.load_extension(f'cogs.{extension}')
await ctx.send(f'Loaded {extension} done.')
@bot.command()
@commands.is_owner()
async def unload(ctx, extension):
await bot.unload_extension(f'cogs.{extension}')
await ctx.send(f'Un - Loaded {extension} done.')
@bot.command()
@commands.is_owner()
async def reload(ctx, extension):
await bot.reload_extension(f'cogs.{extension}')
await ctx.send(f'Re - Loaded {extension} done.')
@bot.event
async def on_tree_error(itn : discord.Interaction, error : app_commands.AppCommandError):
await itn.response.send_message(error, ephemeral=True)
log.warning(f'an error occurred but was handled by the tree error handler, error message : {error}')
@bot.event
async def on_command_error(ctx : commands.context.Context, error : commands.errors.CommandError):
if isinstance(error, commands.errors.CommandNotFound): return
else: await ctx.send(error)
log.warning(f'an error occurred but was handled by the command error handler, error message : {error}')
if __name__ == '__main__':
bot.run(os.getenv('TOKEN'))