-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
88 lines (64 loc) · 3.2 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import discord
from discord import Embed, Color, Member, Intents, Activity, ActivityType, ApplicationContext, DiscordException, Guild
from discord.ext import commands, tasks
from discord.errors import Forbidden
from discord.ext.commands import errors, Context
import json
import logging
from dotenv import load_dotenv
from os import listdir, getenv
from customs import time_now, get_parameter, MyBot
load_dotenv()
bot = MyBot()
@bot.slash_command(name="ping")
async def ping(ctx: ApplicationContext):
latency = round(bot.latency * 1000)
await ctx.respond(f"🏓 Pong! ({latency}ms)", ephemeral=True)
limit = get_parameter('ping_limit')
if latency > limit:
bot.log_action(txt=f"Bot ping is at {latency} ms", level=30)
@bot.slash_command(name="reload", description="Redémarre une cog", brief="Reload a cog", hidden=True, guild_ids=bot.debug_guilds)
@commands.is_owner()
async def reload(ctx: ApplicationContext, extension=None):
if not extension:
for filename_ in listdir('./cogs'):
if filename_.endswith('.py'):
try:
bot.reload_extension(f"cogs.{filename_[:-3]}")
await ctx.respond(f"> Cog `{filename_[:-3]}` successfully reloaded", ephemeral=True)
except discord.ExtensionNotLoaded:
bot.load_extension(f"cogs.{filename_[:-3]}")
await ctx.respond(f"> Cog `{filename_[:-3]}` successfully loaded", ephemeral=True)
else:
try:
bot.reload_extension(f"cogs.{extension}")
await ctx.respond(f"> Cog `{extension}` successfully reloaded", ephemeral=True)
except discord.ExtensionNotLoaded:
try:
bot.load_extension(f"cogs.{extension}")
await ctx.respond(f"> Cog `{extension}` successfully loaded", ephemeral=True)
except discord.ExtensionNotFound:
await ctx.respond(f"> Cog `{extension}` not found", ephemeral=True)
@bot.slash_command(name="load", description="Charge une cog", brief="Load a cog", hidden=True, guild_ids=bot.debug_guilds)
@commands.is_owner()
async def load(ctx: ApplicationContext, extension=None):
try:
bot.load_extension(f"cogs.{extension}")
await ctx.respond(f"> Cog `{extension}` successfully loaded", ephemeral=True)
except discord.ExtensionNotFound:
await ctx.respond(f"> Cog `{extension}` not found", ephemeral=True)
except discord.ExtensionAlreadyLoaded:
await ctx.respond(f"> Cog `{extension}` already loaded", ephemeral=True)
@bot.slash_command(name="unload", description="Décharge une cog", brief="Unload a cog", hidden=True, guild_ids=bot.debug_guilds)
@commands.is_owner()
async def unload(ctx: ApplicationContext, extension=None):
try:
bot.unload_extension(f"cogs.{extension}")
await ctx.respond(f"> Cog `{extension}` successfully unloaded", ephemeral=True)
except discord.ExtensionNotLoaded:
await ctx.respond(f"> Cog `{extension}` not loaded", ephemeral=True)
except discord.ExtensionNotFound:
await ctx.respond(f"> Cog `{extension}` not found", ephemeral=True)
if __name__ == '__main__':
bot.run(getenv("BOT_TOKEN"))
bot.log_action(txt="[BOT] Bot closed.")