diff --git a/app.py b/app.py index 7e87f67..c3a7fe3 100644 --- a/app.py +++ b/app.py @@ -43,82 +43,60 @@ async def on_guild_remove(guild): """Event triggered when the bot leaves a server""" print(f'Bot left server "{guild.name}" (ID: {guild.id})') -# Basic Commands -@bot.command(name='ping') -async def ping(ctx): - """Shows the bot latency""" - latency = round(bot.latency * 1000) - await ctx.send(f'🏓 Pong! Latency: {latency}ms') +# Owner Configuration +OWNER_ID = 253922739709018114 -@bot.command(name='info') -async def info(ctx): - """Shows bot information""" - embed = discord.Embed( - title="🤖 Bot Information", - description="HOI4 ELO Bot - A Discord Bot for Hearts of Iron IV", - color=discord.Color.blue() - ) - embed.add_field(name="Bot Name", value=bot.user.name, inline=True) - embed.add_field(name="Bot ID", value=bot.user.id, inline=True) - embed.add_field(name="Servers", value=len(bot.guilds), inline=True) - embed.add_field(name="Discord.py Version", value=discord.__version__, inline=True) - embed.set_thumbnail(url=bot.user.avatar.url if bot.user.avatar else None) - embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar.url if ctx.author.avatar else None) - - await ctx.send(embed=embed) +# Owner only decorator +def is_owner(): + def predicate(ctx): + return ctx.author.id == OWNER_ID + return commands.check(predicate) -@bot.command(name='help_hoi4') -async def help_hoi4(ctx): - """Shows available HOI4-related commands""" - embed = discord.Embed( - title="📋 HOI4 ELO Bot Commands", - description="Here are the available commands:", - color=discord.Color.green() - ) - - commands_list = [ - ("!ping", "Shows the bot latency"), - ("!info", "Shows bot information"), - ("!help_hoi4", "Shows this help message"), - ("!server_info", "Shows server information"), - ] - - for cmd, desc in commands_list: - embed.add_field(name=cmd, value=desc, inline=False) - - embed.set_footer(text="More commands will be added in future updates!") - await ctx.send(embed=embed) - -@bot.command(name='server_info') -async def server_info(ctx): - """Shows information about the current server""" - guild = ctx.guild - if not guild: - await ctx.send("❌ This command can only be used on a server!") - return - - embed = discord.Embed( - title=f"🏰 Server Information - {guild.name}", - color=discord.Color.orange() - ) - - embed.add_field(name="Server Name", value=guild.name, inline=True) - embed.add_field(name="Server ID", value=guild.id, inline=True) - embed.add_field(name="Members", value=guild.member_count, inline=True) - embed.add_field(name="Created", value=guild.created_at.strftime("%m/%d/%Y"), inline=True) - embed.add_field(name="Boost Level", value=guild.premium_tier, inline=True) - embed.add_field(name="Boost Count", value=guild.premium_subscription_count, inline=True) - - if guild.icon: - embed.set_thumbnail(url=guild.icon.url) - - await ctx.send(embed=embed) +# Owner Commands +@bot.command(name='reload') +@is_owner() +async def reload_bot(ctx): + """Reloads the bot and syncs slash commands (Owner only)""" + try: + # Send initial message + embed = discord.Embed( + title="🔄 Bot Reload", + description="Reloading bot and syncing commands...", + color=discord.Color.yellow() + ) + message = await ctx.send(embed=embed) + + # Sync slash commands + synced = await bot.tree.sync() + + # Update embed with success + embed = discord.Embed( + title="✅ Bot Reloaded Successfully", + description=f"Bot has been reloaded!\nSynced {len(synced)} slash commands.", + color=discord.Color.green() + ) + embed.add_field(name="Servers", value=len(bot.guilds), inline=True) + embed.add_field(name="Latency", value=f"{round(bot.latency * 1000)}ms", inline=True) + embed.set_footer(text=f"Reloaded by {ctx.author}", icon_url=ctx.author.avatar.url if ctx.author.avatar else None) + + await message.edit(embed=embed) + + except Exception as e: + embed = discord.Embed( + title="❌ Reload Failed", + description=f"Error during reload: {str(e)}", + color=discord.Color.red() + ) + await ctx.send(embed=embed) @bot.event async def on_command_error(ctx, error): """Handles command errors""" - if isinstance(error, commands.CommandNotFound): - await ctx.send("❌ Command not found! Use `!help_hoi4` for a list of available commands.") + if isinstance(error, commands.CheckFailure): + await ctx.send("❌ You don't have permission to use this command!") + elif isinstance(error, commands.CommandNotFound): + # Silently ignore command not found errors + pass elif isinstance(error, commands.MissingRequiredArgument): await ctx.send(f"❌ Missing arguments! Command: `{ctx.command}`") elif isinstance(error, commands.BadArgument):