-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (42 loc) · 1.63 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
import discord
import os
from discord.ext import commands
from comandos.guia import GuiaView
TOKEN = os.getenv("TOKEN")
intents: discord.Intents = discord.Intents.all()
def get_prefix(bot: commands.Bot | discord.AutoShardedBot, msg: discord.Message):
if not bot.user:
return ["!"]
return ["!", f"<@{bot.user.id}> ", f"<@!{bot.user.id}> "]
bot = commands.Bot(command_prefix=get_prefix,
intents=intents,
description='Bot oficial del Ejército General del Orden')
@bot.command()
@commands.has_permissions(administrator = True)
async def reload(ctx: commands.Context[commands.Bot], command: str = "", sync: bool = False):
"""Recarga todas las extensiones del bot"""
if command:
extension_name = f"comandos.{command}"
try:
bot.reload_extension(extension_name)
await ctx.send(f"Se recargo el comando: {command}")
except discord.ExtensionNotLoaded:
bot.load_extension(extension_name)
await ctx.send(f"Se cargo el comando: {command}")
except discord.ExtensionNotFound:
await ctx.send(f"No existe el comando: {command}")
else:
extensions = list(bot.extensions.keys())
for extension in extensions:
bot.reload_extension(extension)
await ctx.send('Todas las extensiones han sido recargadas.')
if sync:
await bot.sync_commands()
for filename in os.listdir('./comandos'):
if filename.endswith('.py'):
bot.load_extension(f'comandos.{filename[:-3]}')
# Eventos
@bot.event
async def on_ready():
print(f'Conectado a Discord como {bot.user}')
bot.run(TOKEN)