wpms commited on
Commit
9330668
·
verified ·
1 Parent(s): 9c1493a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +120 -91
main.py CHANGED
@@ -4,6 +4,8 @@ import os
4
  import asyncio
5
  from datetime import datetime
6
  import logging
 
 
7
 
8
  # Setup logging
9
  logging.basicConfig(
@@ -31,12 +33,33 @@ bot = commands.Bot(
31
  case_insensitive=True
32
  )
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Event: Bot ready
35
  @bot.event
36
  async def on_ready():
37
- logger.info(f'✅ Bot logged in as {bot.user.name} ({bot.user.id})')
38
- logger.info(f'🌐 Connected to {len(bot.guilds)} guilds')
39
-
40
  # Set bot status
41
  await bot.change_presence(
42
  activity=discord.Activity(
@@ -45,7 +68,7 @@ async def on_ready():
45
  ),
46
  status=discord.Status.online
47
  )
48
-
49
  # Start background tasks
50
  status_update.start()
51
 
@@ -63,12 +86,12 @@ async def status_update():
63
  # Event: When bot joins a new guild
64
  @bot.event
65
  async def on_guild_join(guild):
66
- logger.info(f'âž• Joined guild: {guild.name} ({guild.id})')
67
 
68
  # Event: When bot leaves a guild
69
  @bot.event
70
  async def on_guild_remove(guild):
71
- logger.info(f'âž– Left guild: {guild.name} ({guild.id})')
72
 
73
  # Event: Handle messages (for non-command messages)
74
  @bot.event
@@ -76,7 +99,7 @@ async def on_message(message):
76
  # Ignore bot messages
77
  if message.author.bot:
78
  return
79
-
80
  # Process commands
81
  await bot.process_commands(message)
82
 
@@ -91,7 +114,7 @@ async def help_command(ctx, command_name: str = None):
91
  command = bot.get_command(command_name)
92
  if command:
93
  embed = discord.Embed(
94
- title=f"📖 Help: !{command.name}",
95
  description=command.help or "No description available",
96
  color=discord.Color.blue()
97
  )
@@ -108,23 +131,23 @@ async def help_command(ctx, command_name: str = None):
108
  )
109
  await ctx.send(embed=embed)
110
  else:
111
- await ctx.send(f"❌ Command `!{command_name}` not found!")
112
  else:
113
  # Show all commands
114
  embed = discord.Embed(
115
- title="🤖 Bot Commands",
116
  description="Here are all available commands:",
117
  color=discord.Color.blue(),
118
  timestamp=datetime.now()
119
  )
120
-
121
  # Categorize commands
122
  categories = {
123
  "General": ['help', 'ping', 'info', 'serverinfo', 'userinfo'],
124
  "Fun": ['say', 'embed', 'poll', '8ball', 'coinflip'],
125
  "Utility": ['avatar', 'invite', 'uptime', 'clear']
126
  }
127
-
128
  for category, cmds in categories.items():
129
  valid_cmds = []
130
  for cmd_name in cmds:
@@ -133,11 +156,11 @@ async def help_command(ctx, command_name: str = None):
133
  valid_cmds.append(f"`!{cmd.name}`")
134
  if valid_cmds:
135
  embed.add_field(
136
- name=f"📁 {category}",
137
  value=" | ".join(valid_cmds),
138
  inline=False
139
  )
140
-
141
  embed.set_footer(text=f"Use !help <command> for more details | Prefix: !")
142
  await ctx.send(embed=embed)
143
 
@@ -146,9 +169,9 @@ async def help_command(ctx, command_name: str = None):
146
  async def ping_command(ctx):
147
  """Check bot latency"""
148
  latency = round(bot.latency * 1000)
149
-
150
  embed = discord.Embed(
151
- title="🏓 Pong!",
152
  description=f"**Latency:** `{latency}ms`\n**API Latency:** `{round(bot.latency * 1000)}ms`",
153
  color=discord.Color.green() if latency < 200 else discord.Color.orange() if latency < 500 else discord.Color.red()
154
  )
@@ -160,12 +183,12 @@ async def ping_command(ctx):
160
  async def info_command(ctx):
161
  """Show bot information"""
162
  embed = discord.Embed(
163
- title="🤖 Bot Information",
164
  description="A Discord bot powered by discord.py",
165
  color=discord.Color.blue(),
166
  timestamp=datetime.now()
167
  )
168
-
169
  embed.add_field(name="Bot Name", value=bot.user.name, inline=True)
170
  embed.add_field(name="Bot ID", value=bot.user.id, inline=True)
171
  embed.add_field(name="Servers", value=len(bot.guilds), inline=True)
@@ -174,10 +197,10 @@ async def info_command(ctx):
174
  embed.add_field(name="Python Version", value="3.10+", inline=True)
175
  embed.add_field(name="Created", value=bot.user.created_at.strftime("%Y-%m-%d"), inline=True)
176
  embed.add_field(name="Uptime", value=get_uptime(), inline=True)
177
-
178
  embed.set_thumbnail(url=bot.user.avatar.url if bot.user.avatar else bot.user.default_avatar.url)
179
- embed.set_footer(text="Made with ❤️ using discord.py")
180
-
181
  await ctx.send(embed=embed)
182
 
183
  # Server Info Command
@@ -185,13 +208,13 @@ async def info_command(ctx):
185
  async def serverinfo_command(ctx):
186
  """Show server information"""
187
  guild = ctx.guild
188
-
189
  embed = discord.Embed(
190
- title=f"📊 {guild.name} Server Info",
191
  color=discord.Color.blue(),
192
  timestamp=datetime.now()
193
  )
194
-
195
  embed.add_field(name="Server ID", value=guild.id, inline=True)
196
  embed.add_field(name="Owner", value=guild.owner.mention if guild.owner else "Unknown", inline=True)
197
  embed.add_field(name="Members", value=guild.member_count, inline=True)
@@ -199,10 +222,10 @@ async def serverinfo_command(ctx):
199
  embed.add_field(name="Roles", value=len(guild.roles), inline=True)
200
  embed.add_field(name="Created", value=guild.created_at.strftime("%Y-%m-%d"), inline=True)
201
  embed.add_field(name="Boost Level", value=f"Level {guild.premium_tier} ({guild.premium_subscription_count} boosts)", inline=True)
202
-
203
  if guild.icon:
204
  embed.set_thumbnail(url=guild.icon.url)
205
-
206
  await ctx.send(embed=embed)
207
 
208
  # User Info Command
@@ -210,13 +233,13 @@ async def serverinfo_command(ctx):
210
  async def userinfo_command(ctx, member: discord.Member = None):
211
  """Show user information"""
212
  member = member or ctx.author
213
-
214
  embed = discord.Embed(
215
- title=f"👤 {member.name}'s Profile",
216
  color=member.color if member.color != discord.Color.default() else discord.Color.blue(),
217
  timestamp=datetime.now()
218
  )
219
-
220
  embed.add_field(name="Username", value=member.name, inline=True)
221
  embed.add_field(name="Display Name", value=member.display_name, inline=True)
222
  embed.add_field(name="ID", value=member.id, inline=True)
@@ -225,14 +248,14 @@ async def userinfo_command(ctx, member: discord.Member = None):
225
  embed.add_field(name="Status", value=str(member.status).title(), inline=True)
226
  embed.add_field(name="Top Role", value=member.top_role.mention, inline=True)
227
  embed.add_field(name="Bot?", value="Yes" if member.bot else "No", inline=True)
228
-
229
  roles = [role.mention for role in member.roles if role != ctx.guild.default_role]
230
  if roles:
231
  embed.add_field(name=f"Roles ({len(roles)})", value=" ".join(roles[:10]) + ("..." if len(roles) > 10 else ""), inline=False)
232
-
233
  embed.set_thumbnail(url=member.avatar.url if member.avatar else member.default_avatar.url)
234
  embed.set_footer(text=f"Requested by {ctx.author.name}")
235
-
236
  await ctx.send(embed=embed)
237
 
238
  # Avatar Command
@@ -240,16 +263,16 @@ async def userinfo_command(ctx, member: discord.Member = None):
240
  async def avatar_command(ctx, member: discord.Member = None):
241
  """Show user's avatar"""
242
  member = member or ctx.author
243
-
244
  embed = discord.Embed(
245
- title=f"🖼️ {member.name}'s Avatar",
246
  color=discord.Color.blue()
247
  )
248
-
249
  avatar_url = member.avatar.url if member.avatar else member.default_avatar.url
250
  embed.set_image(url=avatar_url)
251
  embed.add_field(name="Links", value=f"[PNG]({member.avatar.url if member.avatar else member.default_avatar.url}) | [WEBP]({member.avatar.url if member.avatar else member.default_avatar.url})", inline=False)
252
-
253
  await ctx.send(embed=embed)
254
 
255
  # Say Command
@@ -276,54 +299,54 @@ async def embed_command(ctx, *, message: str):
276
  async def poll_command(ctx, *, question: str):
277
  """Create a poll"""
278
  embed = discord.Embed(
279
- title="📊 Poll",
280
  description=question,
281
  color=discord.Color.blue(),
282
  timestamp=datetime.now()
283
  )
284
  embed.set_footer(text=f"Poll by {ctx.author.name}")
285
-
286
  poll_message = await ctx.send(embed=embed)
287
- await poll_message.add_reaction("👍")
288
- await poll_message.add_reaction("👎")
289
- await poll_message.add_reaction("🤷")
290
 
291
  # 8Ball Command
292
  @bot.command(name='8ball', aliases=['magic8ball', 'ask'])
293
  async def eightball_command(ctx, *, question: str):
294
  """Ask the magic 8-ball"""
295
  import random
296
-
297
  responses = [
298
- "🎱 It is certain.",
299
- "🎱 It is decidedly so.",
300
- "🎱 Without a doubt.",
301
- "🎱 Yes definitely.",
302
- "🎱 You may rely on it.",
303
- "🎱 As I see it, yes.",
304
- "🎱 Most likely.",
305
- "🎱 Outlook good.",
306
- "🎱 Yes.",
307
- "🎱 Signs point to yes.",
308
- "🎱 Reply hazy, try again.",
309
- "🎱 Ask again later.",
310
- "🎱 Better not tell you now.",
311
- "🎱 Cannot predict now.",
312
- "🎱 Concentrate and ask again.",
313
- "🎱 Don't count on it.",
314
- "🎱 My reply is no.",
315
- "🎱 My sources say no.",
316
- "🎱 Outlook not so good.",
317
- "🎱 Very doubtful."
318
  ]
319
-
320
  embed = discord.Embed(
321
- title="🎱 Magic 8-Ball",
322
  color=discord.Color.purple()
323
  )
324
  embed.add_field(name="Question", value=question, inline=False)
325
  embed.add_field(name="Answer", value=random.choice(responses), inline=False)
326
-
327
  await ctx.send(embed=embed)
328
 
329
  # Coin Flip Command
@@ -331,16 +354,16 @@ async def eightball_command(ctx, *, question: str):
331
  async def coinflip_command(ctx):
332
  """Flip a coin"""
333
  import random
334
-
335
  result = random.choice(["Heads", "Tails"])
336
- emoji = "🪙" if result == "Heads" else "🪙"
337
-
338
  embed = discord.Embed(
339
  title=f"{emoji} Coin Flip",
340
  description=f"**Result:** {result}",
341
  color=discord.Color.gold()
342
  )
343
-
344
  await ctx.send(embed=embed)
345
 
346
  # Invite Command
@@ -359,16 +382,16 @@ async def invite_command(ctx):
359
  connect=True,
360
  speak=True
361
  )
362
-
363
  invite_url = discord.utils.oauth_url(bot.user.id, permissions=permissions)
364
-
365
  embed = discord.Embed(
366
- title="🔗 Invite Bot",
367
  description=f"[Click here to invite me!]({invite_url})",
368
  color=discord.Color.green()
369
  )
370
  embed.add_field(name="Bot ID", value=bot.user.id, inline=False)
371
-
372
  await ctx.send(embed=embed)
373
 
374
  # Clear Command
@@ -377,12 +400,12 @@ async def invite_command(ctx):
377
  async def clear_command(ctx, amount: int = 5):
378
  """Clear messages (requires Manage Messages permission)"""
379
  if amount < 1 or amount > 100:
380
- await ctx.send("❌ Please specify a number between 1 and 100!")
381
  return
382
-
383
  deleted = await ctx.channel.purge(limit=amount + 1)
384
  embed = discord.Embed(
385
- description=f"🗑️ Deleted {len(deleted) - 1} messages!",
386
  color=discord.Color.green()
387
  )
388
  msg = await ctx.send(embed=embed)
@@ -394,7 +417,7 @@ async def clear_command(ctx, amount: int = 5):
394
  async def uptime_command(ctx):
395
  """Show bot uptime"""
396
  embed = discord.Embed(
397
- title="⏱️ Bot Uptime",
398
  description=get_uptime(),
399
  color=discord.Color.blue()
400
  )
@@ -405,35 +428,35 @@ async def uptime_command(ctx):
405
  async def on_command_error(ctx, error):
406
  if isinstance(error, commands.CommandNotFound):
407
  return # Ignore unknown commands
408
-
409
  elif isinstance(error, commands.MissingRequiredArgument):
410
  embed = discord.Embed(
411
- title="❌ Missing Argument",
412
  description=f"Missing required argument: `{error.param.name}`\nUse `!help {ctx.command.name}` for usage info.",
413
  color=discord.Color.red()
414
  )
415
  await ctx.send(embed=embed)
416
-
417
  elif isinstance(error, commands.MissingPermissions):
418
  embed = discord.Embed(
419
- title="❌ Missing Permissions",
420
  description=f"You need `{', '.join(error.missing_permissions)}` permission to use this command.",
421
  color=discord.Color.red()
422
  )
423
  await ctx.send(embed=embed)
424
-
425
  elif isinstance(error, commands.MemberNotFound):
426
  embed = discord.Embed(
427
- title="❌ User Not Found",
428
  description="The specified user was not found.",
429
  color=discord.Color.red()
430
  )
431
  await ctx.send(embed=embed)
432
-
433
  else:
434
  logger.error(f"Command error: {error}")
435
  embed = discord.Embed(
436
- title="❌ Error",
437
  description="An unexpected error occurred. Please try again later.",
438
  color=discord.Color.red()
439
  )
@@ -447,7 +470,7 @@ def get_uptime():
447
  days = delta.days
448
  hours, remainder = divmod(delta.seconds, 3600)
449
  minutes, seconds = divmod(remainder, 60)
450
-
451
  parts = []
452
  if days > 0:
453
  parts.append(f"{days}d")
@@ -456,13 +479,19 @@ def get_uptime():
456
  if minutes > 0:
457
  parts.append(f"{minutes}m")
458
  parts.append(f"{seconds}s")
459
-
460
  return " ".join(parts)
461
 
462
- # Run the bot
 
 
 
 
 
 
463
  if __name__ == "__main__":
464
  try:
465
- bot.run(TOKEN)
466
  except Exception as e:
467
- logger.error(f"Failed to start bot: {e}")
468
- raise
 
4
  import asyncio
5
  from datetime import datetime
6
  import logging
7
+ from aiohttp import web
8
+ import threading
9
 
10
  # Setup logging
11
  logging.basicConfig(
 
33
  case_insensitive=True
34
  )
35
 
36
+ # ==================== HTTP SERVER ====================
37
+
38
+ async def health_check(request):
39
+ """Simple health check endpoint"""
40
+ return web.Response(text="hey, bot started✅")
41
+
42
+ async def start_http_server():
43
+ """Start HTTP server for health checks"""
44
+ app = web.Application()
45
+ app.router.add_get('/', health_check)
46
+ app.router.add_get('/health', health_check)
47
+
48
+ runner = web.AppRunner(app)
49
+ await runner.setup()
50
+
51
+ port = int(os.getenv('PORT', 7860))
52
+ site = web.TCPSite(runner, '0.0.0.0', port)
53
+ await site.start()
54
+
55
+ logger.info(f"🌐 HTTP server started on port {port}")
56
+
57
  # Event: Bot ready
58
  @bot.event
59
  async def on_ready():
60
+ logger.info(f'✅ Bot logged in as {bot.user.name} ({bot.user.id})')
61
+ logger.info(f'🌐 Connected to {len(bot.guilds)} guilds')
62
+
63
  # Set bot status
64
  await bot.change_presence(
65
  activity=discord.Activity(
 
68
  ),
69
  status=discord.Status.online
70
  )
71
+
72
  # Start background tasks
73
  status_update.start()
74
 
 
86
  # Event: When bot joins a new guild
87
  @bot.event
88
  async def on_guild_join(guild):
89
+ logger.info(f'➕ Joined guild: {guild.name} ({guild.id})')
90
 
91
  # Event: When bot leaves a guild
92
  @bot.event
93
  async def on_guild_remove(guild):
94
+ logger.info(f'➖ Left guild: {guild.name} ({guild.id})')
95
 
96
  # Event: Handle messages (for non-command messages)
97
  @bot.event
 
99
  # Ignore bot messages
100
  if message.author.bot:
101
  return
102
+
103
  # Process commands
104
  await bot.process_commands(message)
105
 
 
114
  command = bot.get_command(command_name)
115
  if command:
116
  embed = discord.Embed(
117
+ title=f"📖 Help: !{command.name}",
118
  description=command.help or "No description available",
119
  color=discord.Color.blue()
120
  )
 
131
  )
132
  await ctx.send(embed=embed)
133
  else:
134
+ await ctx.send(f"❌ Command `!{command_name}` not found!")
135
  else:
136
  # Show all commands
137
  embed = discord.Embed(
138
+ title="🤖 Bot Commands",
139
  description="Here are all available commands:",
140
  color=discord.Color.blue(),
141
  timestamp=datetime.now()
142
  )
143
+
144
  # Categorize commands
145
  categories = {
146
  "General": ['help', 'ping', 'info', 'serverinfo', 'userinfo'],
147
  "Fun": ['say', 'embed', 'poll', '8ball', 'coinflip'],
148
  "Utility": ['avatar', 'invite', 'uptime', 'clear']
149
  }
150
+
151
  for category, cmds in categories.items():
152
  valid_cmds = []
153
  for cmd_name in cmds:
 
156
  valid_cmds.append(f"`!{cmd.name}`")
157
  if valid_cmds:
158
  embed.add_field(
159
+ name=f"📁 {category}",
160
  value=" | ".join(valid_cmds),
161
  inline=False
162
  )
163
+
164
  embed.set_footer(text=f"Use !help <command> for more details | Prefix: !")
165
  await ctx.send(embed=embed)
166
 
 
169
  async def ping_command(ctx):
170
  """Check bot latency"""
171
  latency = round(bot.latency * 1000)
172
+
173
  embed = discord.Embed(
174
+ title="🏓 Pong!",
175
  description=f"**Latency:** `{latency}ms`\n**API Latency:** `{round(bot.latency * 1000)}ms`",
176
  color=discord.Color.green() if latency < 200 else discord.Color.orange() if latency < 500 else discord.Color.red()
177
  )
 
183
  async def info_command(ctx):
184
  """Show bot information"""
185
  embed = discord.Embed(
186
+ title="🤖 Bot Information",
187
  description="A Discord bot powered by discord.py",
188
  color=discord.Color.blue(),
189
  timestamp=datetime.now()
190
  )
191
+
192
  embed.add_field(name="Bot Name", value=bot.user.name, inline=True)
193
  embed.add_field(name="Bot ID", value=bot.user.id, inline=True)
194
  embed.add_field(name="Servers", value=len(bot.guilds), inline=True)
 
197
  embed.add_field(name="Python Version", value="3.10+", inline=True)
198
  embed.add_field(name="Created", value=bot.user.created_at.strftime("%Y-%m-%d"), inline=True)
199
  embed.add_field(name="Uptime", value=get_uptime(), inline=True)
200
+
201
  embed.set_thumbnail(url=bot.user.avatar.url if bot.user.avatar else bot.user.default_avatar.url)
202
+ embed.set_footer(text="Made with ❤️ using discord.py")
203
+
204
  await ctx.send(embed=embed)
205
 
206
  # Server Info Command
 
208
  async def serverinfo_command(ctx):
209
  """Show server information"""
210
  guild = ctx.guild
211
+
212
  embed = discord.Embed(
213
+ title=f"📊 {guild.name} Server Info",
214
  color=discord.Color.blue(),
215
  timestamp=datetime.now()
216
  )
217
+
218
  embed.add_field(name="Server ID", value=guild.id, inline=True)
219
  embed.add_field(name="Owner", value=guild.owner.mention if guild.owner else "Unknown", inline=True)
220
  embed.add_field(name="Members", value=guild.member_count, inline=True)
 
222
  embed.add_field(name="Roles", value=len(guild.roles), inline=True)
223
  embed.add_field(name="Created", value=guild.created_at.strftime("%Y-%m-%d"), inline=True)
224
  embed.add_field(name="Boost Level", value=f"Level {guild.premium_tier} ({guild.premium_subscription_count} boosts)", inline=True)
225
+
226
  if guild.icon:
227
  embed.set_thumbnail(url=guild.icon.url)
228
+
229
  await ctx.send(embed=embed)
230
 
231
  # User Info Command
 
233
  async def userinfo_command(ctx, member: discord.Member = None):
234
  """Show user information"""
235
  member = member or ctx.author
236
+
237
  embed = discord.Embed(
238
+ title=f"👤 {member.name}'s Profile",
239
  color=member.color if member.color != discord.Color.default() else discord.Color.blue(),
240
  timestamp=datetime.now()
241
  )
242
+
243
  embed.add_field(name="Username", value=member.name, inline=True)
244
  embed.add_field(name="Display Name", value=member.display_name, inline=True)
245
  embed.add_field(name="ID", value=member.id, inline=True)
 
248
  embed.add_field(name="Status", value=str(member.status).title(), inline=True)
249
  embed.add_field(name="Top Role", value=member.top_role.mention, inline=True)
250
  embed.add_field(name="Bot?", value="Yes" if member.bot else "No", inline=True)
251
+
252
  roles = [role.mention for role in member.roles if role != ctx.guild.default_role]
253
  if roles:
254
  embed.add_field(name=f"Roles ({len(roles)})", value=" ".join(roles[:10]) + ("..." if len(roles) > 10 else ""), inline=False)
255
+
256
  embed.set_thumbnail(url=member.avatar.url if member.avatar else member.default_avatar.url)
257
  embed.set_footer(text=f"Requested by {ctx.author.name}")
258
+
259
  await ctx.send(embed=embed)
260
 
261
  # Avatar Command
 
263
  async def avatar_command(ctx, member: discord.Member = None):
264
  """Show user's avatar"""
265
  member = member or ctx.author
266
+
267
  embed = discord.Embed(
268
+ title=f"🖼️ {member.name}'s Avatar",
269
  color=discord.Color.blue()
270
  )
271
+
272
  avatar_url = member.avatar.url if member.avatar else member.default_avatar.url
273
  embed.set_image(url=avatar_url)
274
  embed.add_field(name="Links", value=f"[PNG]({member.avatar.url if member.avatar else member.default_avatar.url}) | [WEBP]({member.avatar.url if member.avatar else member.default_avatar.url})", inline=False)
275
+
276
  await ctx.send(embed=embed)
277
 
278
  # Say Command
 
299
  async def poll_command(ctx, *, question: str):
300
  """Create a poll"""
301
  embed = discord.Embed(
302
+ title="📊 Poll",
303
  description=question,
304
  color=discord.Color.blue(),
305
  timestamp=datetime.now()
306
  )
307
  embed.set_footer(text=f"Poll by {ctx.author.name}")
308
+
309
  poll_message = await ctx.send(embed=embed)
310
+ await poll_message.add_reaction("👍")
311
+ await poll_message.add_reaction("👎")
312
+ await poll_message.add_reaction("🤷")
313
 
314
  # 8Ball Command
315
  @bot.command(name='8ball', aliases=['magic8ball', 'ask'])
316
  async def eightball_command(ctx, *, question: str):
317
  """Ask the magic 8-ball"""
318
  import random
319
+
320
  responses = [
321
+ "🎱 It is certain.",
322
+ "🎱 It is decidedly so.",
323
+ "🎱 Without a doubt.",
324
+ "🎱 Yes definitely.",
325
+ "🎱 You may rely on it.",
326
+ "🎱 As I see it, yes.",
327
+ "🎱 Most likely.",
328
+ "🎱 Outlook good.",
329
+ "🎱 Yes.",
330
+ "🎱 Signs point to yes.",
331
+ "🎱 Reply hazy, try again.",
332
+ "🎱 Ask again later.",
333
+ "🎱 Better not tell you now.",
334
+ "🎱 Cannot predict now.",
335
+ "🎱 Concentrate and ask again.",
336
+ "🎱 Don't count on it.",
337
+ "🎱 My reply is no.",
338
+ "🎱 My sources say no.",
339
+ "🎱 Outlook not so good.",
340
+ "🎱 Very doubtful."
341
  ]
342
+
343
  embed = discord.Embed(
344
+ title="🎱 Magic 8-Ball",
345
  color=discord.Color.purple()
346
  )
347
  embed.add_field(name="Question", value=question, inline=False)
348
  embed.add_field(name="Answer", value=random.choice(responses), inline=False)
349
+
350
  await ctx.send(embed=embed)
351
 
352
  # Coin Flip Command
 
354
  async def coinflip_command(ctx):
355
  """Flip a coin"""
356
  import random
357
+
358
  result = random.choice(["Heads", "Tails"])
359
+ emoji = "🪙" if result == "Heads" else "🪙"
360
+
361
  embed = discord.Embed(
362
  title=f"{emoji} Coin Flip",
363
  description=f"**Result:** {result}",
364
  color=discord.Color.gold()
365
  )
366
+
367
  await ctx.send(embed=embed)
368
 
369
  # Invite Command
 
382
  connect=True,
383
  speak=True
384
  )
385
+
386
  invite_url = discord.utils.oauth_url(bot.user.id, permissions=permissions)
387
+
388
  embed = discord.Embed(
389
+ title="🔗 Invite Bot",
390
  description=f"[Click here to invite me!]({invite_url})",
391
  color=discord.Color.green()
392
  )
393
  embed.add_field(name="Bot ID", value=bot.user.id, inline=False)
394
+
395
  await ctx.send(embed=embed)
396
 
397
  # Clear Command
 
400
  async def clear_command(ctx, amount: int = 5):
401
  """Clear messages (requires Manage Messages permission)"""
402
  if amount < 1 or amount > 100:
403
+ await ctx.send("❌ Please specify a number between 1 and 100!")
404
  return
405
+
406
  deleted = await ctx.channel.purge(limit=amount + 1)
407
  embed = discord.Embed(
408
+ description=f"🗑️ Deleted {len(deleted) - 1} messages!",
409
  color=discord.Color.green()
410
  )
411
  msg = await ctx.send(embed=embed)
 
417
  async def uptime_command(ctx):
418
  """Show bot uptime"""
419
  embed = discord.Embed(
420
+ title="⏱️ Bot Uptime",
421
  description=get_uptime(),
422
  color=discord.Color.blue()
423
  )
 
428
  async def on_command_error(ctx, error):
429
  if isinstance(error, commands.CommandNotFound):
430
  return # Ignore unknown commands
431
+
432
  elif isinstance(error, commands.MissingRequiredArgument):
433
  embed = discord.Embed(
434
+ title="❌ Missing Argument",
435
  description=f"Missing required argument: `{error.param.name}`\nUse `!help {ctx.command.name}` for usage info.",
436
  color=discord.Color.red()
437
  )
438
  await ctx.send(embed=embed)
439
+
440
  elif isinstance(error, commands.MissingPermissions):
441
  embed = discord.Embed(
442
+ title="❌ Missing Permissions",
443
  description=f"You need `{', '.join(error.missing_permissions)}` permission to use this command.",
444
  color=discord.Color.red()
445
  )
446
  await ctx.send(embed=embed)
447
+
448
  elif isinstance(error, commands.MemberNotFound):
449
  embed = discord.Embed(
450
+ title="❌ User Not Found",
451
  description="The specified user was not found.",
452
  color=discord.Color.red()
453
  )
454
  await ctx.send(embed=embed)
455
+
456
  else:
457
  logger.error(f"Command error: {error}")
458
  embed = discord.Embed(
459
+ title="❌ Error",
460
  description="An unexpected error occurred. Please try again later.",
461
  color=discord.Color.red()
462
  )
 
470
  days = delta.days
471
  hours, remainder = divmod(delta.seconds, 3600)
472
  minutes, seconds = divmod(remainder, 60)
473
+
474
  parts = []
475
  if days > 0:
476
  parts.append(f"{days}d")
 
479
  if minutes > 0:
480
  parts.append(f"{minutes}m")
481
  parts.append(f"{seconds}s")
482
+
483
  return " ".join(parts)
484
 
485
+ # Run both HTTP server and Discord bot
486
+ async def main():
487
+ await asyncio.gather(
488
+ start_http_server(),
489
+ bot.start(TOKEN)
490
+ )
491
+
492
  if __name__ == "__main__":
493
  try:
494
+ asyncio.run(main())
495
  except Exception as e:
496
+ logger.error(f"Failed to start: {e}")
497
+ raise