modified: app.py
This commit is contained in:
96
app.py
96
app.py
@@ -43,82 +43,60 @@ async def on_guild_remove(guild):
|
|||||||
"""Event triggered when the bot leaves a server"""
|
"""Event triggered when the bot leaves a server"""
|
||||||
print(f'Bot left server "{guild.name}" (ID: {guild.id})')
|
print(f'Bot left server "{guild.name}" (ID: {guild.id})')
|
||||||
|
|
||||||
# Basic Commands
|
# Owner Configuration
|
||||||
@bot.command(name='ping')
|
OWNER_ID = 253922739709018114
|
||||||
async def ping(ctx):
|
|
||||||
"""Shows the bot latency"""
|
|
||||||
latency = round(bot.latency * 1000)
|
|
||||||
await ctx.send(f'🏓 Pong! Latency: {latency}ms')
|
|
||||||
|
|
||||||
@bot.command(name='info')
|
# Owner only decorator
|
||||||
async def info(ctx):
|
def is_owner():
|
||||||
"""Shows bot information"""
|
def predicate(ctx):
|
||||||
|
return ctx.author.id == OWNER_ID
|
||||||
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
# 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(
|
embed = discord.Embed(
|
||||||
title="🤖 Bot Information",
|
title="🔄 Bot Reload",
|
||||||
description="HOI4 ELO Bot - A Discord Bot for Hearts of Iron IV",
|
description="Reloading bot and syncing commands...",
|
||||||
color=discord.Color.blue()
|
color=discord.Color.yellow()
|
||||||
)
|
)
|
||||||
embed.add_field(name="Bot Name", value=bot.user.name, inline=True)
|
message = await ctx.send(embed=embed)
|
||||||
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)
|
# Sync slash commands
|
||||||
|
synced = await bot.tree.sync()
|
||||||
|
|
||||||
@bot.command(name='help_hoi4')
|
# Update embed with success
|
||||||
async def help_hoi4(ctx):
|
|
||||||
"""Shows available HOI4-related commands"""
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="📋 HOI4 ELO Bot Commands",
|
title="✅ Bot Reloaded Successfully",
|
||||||
description="Here are the available commands:",
|
description=f"Bot has been reloaded!\nSynced {len(synced)} slash commands.",
|
||||||
color=discord.Color.green()
|
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)
|
||||||
|
|
||||||
commands_list = [
|
await message.edit(embed=embed)
|
||||||
("!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
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=f"🏰 Server Information - {guild.name}",
|
title="❌ Reload Failed",
|
||||||
color=discord.Color.orange()
|
description=f"Error during reload: {str(e)}",
|
||||||
|
color=discord.Color.red()
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_command_error(ctx, error):
|
async def on_command_error(ctx, error):
|
||||||
"""Handles command errors"""
|
"""Handles command errors"""
|
||||||
if isinstance(error, commands.CommandNotFound):
|
if isinstance(error, commands.CheckFailure):
|
||||||
await ctx.send("❌ Command not found! Use `!help_hoi4` for a list of available commands.")
|
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):
|
elif isinstance(error, commands.MissingRequiredArgument):
|
||||||
await ctx.send(f"❌ Missing arguments! Command: `{ctx.command}`")
|
await ctx.send(f"❌ Missing arguments! Command: `{ctx.command}`")
|
||||||
elif isinstance(error, commands.BadArgument):
|
elif isinstance(error, commands.BadArgument):
|
||||||
|
|||||||
Reference in New Issue
Block a user