wpms commited on
Commit
c340747
·
verified ·
1 Parent(s): 6db8218

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +237 -140
main.py CHANGED
@@ -1,11 +1,13 @@
1
  import discord
2
  from discord.ext import commands, tasks
 
3
  import os
4
  import asyncio
5
  from datetime import datetime
6
  import logging
7
  from flask import Flask
8
  from threading import Thread
 
9
 
10
  # Setup logging
11
  logging.basicConfig(
@@ -22,7 +24,7 @@ def home():
22
  return "hey, bot started✅"
23
 
24
  def run_web():
25
- app.run(host='0.0.0.0', port=7860)
26
 
27
  # Start web server in a thread
28
  web_thread = Thread(target=run_web)
@@ -35,15 +37,15 @@ if not TOKEN:
35
 
36
  # Bot intents
37
  intents = discord.Intents.default()
38
- intents.message_content = True # Required for reading message content
39
  intents.members = True
40
  intents.presences = True
41
 
42
- # Create bot instance
43
  bot = commands.Bot(
44
- command_prefix='!',
45
  intents=intents,
46
- help_command=None, # Custom help command
47
  case_insensitive=True
48
  )
49
 
@@ -53,11 +55,18 @@ async def on_ready():
53
  logger.info(f'✅ Bot logged in as {bot.user.name} ({bot.user.id})')
54
  logger.info(f'🌐 Connected to {len(bot.guilds)} guilds')
55
 
 
 
 
 
 
 
 
56
  # Set bot status
57
  await bot.change_presence(
58
  activity=discord.Activity(
59
  type=discord.ActivityType.watching,
60
- name=f"{len(bot.guilds)} servers | !help"
61
  ),
62
  status=discord.Status.online
63
  )
@@ -71,7 +80,7 @@ async def status_update():
71
  await bot.change_presence(
72
  activity=discord.Activity(
73
  type=discord.ActivityType.watching,
74
- name=f"{len(bot.guilds)} servers | !help"
75
  ),
76
  status=discord.Status.online
77
  )
@@ -86,94 +95,178 @@ async def on_guild_join(guild):
86
  async def on_guild_remove(guild):
87
  logger.info(f'➖ Left guild: {guild.name} ({guild.id})')
88
 
89
- # Event: Handle messages (for non-command messages)
90
- @bot.event
91
- async def on_message(message):
92
- # Ignore bot messages
93
- if message.author.bot:
94
- return
95
-
96
- # Process commands
97
- await bot.process_commands(message)
98
-
99
- # ==================== COMMANDS ====================
100
-
101
- # Help Command
102
- @bot.command(name='help', aliases=['h', 'commands'])
103
- async def help_command(ctx, command_name: str = None):
 
 
 
 
 
 
 
104
  """Show help information"""
105
  if command_name:
106
  # Show specific command help
107
- command = bot.get_command(command_name)
108
- if command:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  embed = discord.Embed(
110
- title=f"📖 Help: !{command.name}",
111
- description=command.help or "No description available",
112
  color=discord.Color.blue()
113
  )
114
- embed.add_field(
115
- name="Usage",
116
- value=f"`!{command.name} {command.signature}`" if command.signature else f"`!{command.name}`",
117
- inline=False
118
- )
119
- if command.aliases:
120
- embed.add_field(
121
- name="Aliases",
122
- value=", ".join([f"`!{alias}`" for alias in command.aliases]),
123
- inline=False
124
- )
125
- await ctx.send(embed=embed)
126
  else:
127
- await ctx.send(f"❌ Command `!{command_name}` not found!")
128
  else:
129
- # Show all commands
130
  embed = discord.Embed(
131
  title="🤖 Bot Commands",
132
- description="Here are all available commands:",
133
  color=discord.Color.blue(),
134
  timestamp=datetime.now()
135
  )
136
 
137
  # Categorize commands
138
  categories = {
139
- "General": ['help', 'ping', 'info', 'serverinfo', 'userinfo'],
140
- "Fun": ['say', 'embed', 'poll', '8ball', 'coinflip'],
141
- "Utility": ['avatar', 'invite', 'uptime', 'clear']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
143
 
144
  for category, cmds in categories.items():
145
- valid_cmds = []
146
- for cmd_name in cmds:
147
- cmd = bot.get_command(cmd_name)
148
- if cmd:
149
- valid_cmds.append(f"`!{cmd.name}`")
150
- if valid_cmds:
151
- embed.add_field(
152
- name=f"📁 {category}",
153
- value=" | ".join(valid_cmds),
154
- inline=False
155
- )
156
 
157
- embed.set_footer(text=f"Use !help <command> for more details | Prefix: !")
158
- await ctx.send(embed=embed)
159
 
160
  # Ping Command
161
- @bot.command(name='ping', aliases=['latency'])
162
- async def ping_command(ctx):
163
  """Check bot latency"""
164
  latency = round(bot.latency * 1000)
165
 
 
 
166
  embed = discord.Embed(
167
  title="🏓 Pong!",
168
  description=f"**Latency:** `{latency}ms`\n**API Latency:** `{round(bot.latency * 1000)}ms`",
169
- color=discord.Color.green() if latency < 200 else discord.Color.orange() if latency < 500 else discord.Color.red()
170
  )
171
- embed.set_footer(text=f"Requested by {ctx.author.name}")
172
- await ctx.send(embed=embed)
173
 
174
  # Info Command
175
- @bot.command(name='info', aliases=['botinfo', 'about'])
176
- async def info_command(ctx):
177
  """Show bot information"""
178
  embed = discord.Embed(
179
  title="🤖 Bot Information",
@@ -194,13 +287,13 @@ async def info_command(ctx):
194
  embed.set_thumbnail(url=bot.user.avatar.url if bot.user.avatar else bot.user.default_avatar.url)
195
  embed.set_footer(text="Made with ❤️ using discord.py")
196
 
197
- await ctx.send(embed=embed)
198
 
199
  # Server Info Command
200
- @bot.command(name='serverinfo', aliases=['server', 'guildinfo'])
201
- async def serverinfo_command(ctx):
202
  """Show server information"""
203
- guild = ctx.guild
204
 
205
  embed = discord.Embed(
206
  title=f"📊 {guild.name} Server Info",
@@ -219,13 +312,14 @@ async def serverinfo_command(ctx):
219
  if guild.icon:
220
  embed.set_thumbnail(url=guild.icon.url)
221
 
222
- await ctx.send(embed=embed)
223
 
224
  # User Info Command
225
- @bot.command(name='userinfo', aliases=['whois', 'profile'])
226
- async def userinfo_command(ctx, member: discord.Member = None):
 
227
  """Show user information"""
228
- member = member or ctx.author
229
 
230
  embed = discord.Embed(
231
  title=f"👤 {member.name}'s Profile",
@@ -242,20 +336,21 @@ async def userinfo_command(ctx, member: discord.Member = None):
242
  embed.add_field(name="Top Role", value=member.top_role.mention, inline=True)
243
  embed.add_field(name="Bot?", value="Yes" if member.bot else "No", inline=True)
244
 
245
- roles = [role.mention for role in member.roles if role != ctx.guild.default_role]
246
  if roles:
247
  embed.add_field(name=f"Roles ({len(roles)})", value=" ".join(roles[:10]) + ("..." if len(roles) > 10 else ""), inline=False)
248
 
249
  embed.set_thumbnail(url=member.avatar.url if member.avatar else member.default_avatar.url)
250
- embed.set_footer(text=f"Requested by {ctx.author.name}")
251
 
252
- await ctx.send(embed=embed)
253
 
254
  # Avatar Command
255
- @bot.command(name='avatar', aliases=['av', 'pfp'])
256
- async def avatar_command(ctx, member: discord.Member = None):
 
257
  """Show user's avatar"""
258
- member = member or ctx.author
259
 
260
  embed = discord.Embed(
261
  title=f"🖼️ {member.name}'s Avatar",
@@ -264,32 +359,34 @@ async def avatar_command(ctx, member: discord.Member = None):
264
 
265
  avatar_url = member.avatar.url if member.avatar else member.default_avatar.url
266
  embed.set_image(url=avatar_url)
267
- 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)
268
 
269
- await ctx.send(embed=embed)
270
 
271
  # Say Command
272
- @bot.command(name='say', aliases=['echo'])
273
- async def say_command(ctx, *, message: str):
 
274
  """Make the bot say something"""
275
- await ctx.message.delete()
276
- await ctx.send(message)
277
 
278
  # Embed Command
279
- @bot.command(name='embed', aliases=['em'])
280
- async def embed_command(ctx, *, message: str):
 
281
  """Create a custom embed"""
282
  embed = discord.Embed(
283
  description=message,
284
  color=discord.Color.blue(),
285
  timestamp=datetime.now()
286
  )
287
- embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url if ctx.author.avatar else ctx.author.default_avatar.url)
288
- await ctx.send(embed=embed)
289
 
290
  # Poll Command
291
- @bot.command(name='poll', aliases=['vote'])
292
- async def poll_command(ctx, *, question: str):
 
293
  """Create a poll"""
294
  embed = discord.Embed(
295
  title="📊 Poll",
@@ -297,19 +394,19 @@ async def poll_command(ctx, *, question: str):
297
  color=discord.Color.blue(),
298
  timestamp=datetime.now()
299
  )
300
- embed.set_footer(text=f"Poll by {ctx.author.name}")
301
 
302
- poll_message = await ctx.send(embed=embed)
 
303
  await poll_message.add_reaction("👍")
304
  await poll_message.add_reaction("👎")
305
  await poll_message.add_reaction("🤷")
306
 
307
  # 8Ball Command
308
- @bot.command(name='8ball', aliases=['magic8ball', 'ask'])
309
- async def eightball_command(ctx, *, question: str):
 
310
  """Ask the magic 8-ball"""
311
- import random
312
-
313
  responses = [
314
  "🎱 It is certain.",
315
  "🎱 It is decidedly so.",
@@ -340,28 +437,25 @@ async def eightball_command(ctx, *, question: str):
340
  embed.add_field(name="Question", value=question, inline=False)
341
  embed.add_field(name="Answer", value=random.choice(responses), inline=False)
342
 
343
- await ctx.send(embed=embed)
344
 
345
  # Coin Flip Command
346
- @bot.command(name='coinflip', aliases=['flip', 'coin'])
347
- async def coinflip_command(ctx):
348
  """Flip a coin"""
349
- import random
350
-
351
  result = random.choice(["Heads", "Tails"])
352
- emoji = "🪙" if result == "Heads" else "🪙"
353
 
354
  embed = discord.Embed(
355
- title=f"{emoji} Coin Flip",
356
  description=f"**Result:** {result}",
357
  color=discord.Color.gold()
358
  )
359
 
360
- await ctx.send(embed=embed)
361
 
362
  # Invite Command
363
- @bot.command(name='invite', aliases=['addbot'])
364
- async def invite_command(ctx):
365
  """Get bot invite link"""
366
  permissions = discord.Permissions(
367
  send_messages=True,
@@ -385,75 +479,78 @@ async def invite_command(ctx):
385
  )
386
  embed.add_field(name="Bot ID", value=bot.user.id, inline=False)
387
 
388
- await ctx.send(embed=embed)
389
 
390
  # Clear Command
391
- @bot.command(name='clear', aliases=['purge', 'clean'])
392
- @commands.has_permissions(manage_messages=True)
393
- async def clear_command(ctx, amount: int = 5):
 
394
  """Clear messages (requires Manage Messages permission)"""
395
  if amount < 1 or amount > 100:
396
- await ctx.send("❌ Please specify a number between 1 and 100!")
397
  return
398
 
399
- deleted = await ctx.channel.purge(limit=amount + 1)
 
400
  embed = discord.Embed(
401
- description=f"🗑️ Deleted {len(deleted) - 1} messages!",
402
  color=discord.Color.green()
403
  )
404
- msg = await ctx.send(embed=embed)
405
  await asyncio.sleep(3)
406
- await msg.delete()
 
 
 
407
 
408
  # Uptime Command
409
- @bot.command(name='uptime', aliases=['up'])
410
- async def uptime_command(ctx):
411
  """Show bot uptime"""
412
  embed = discord.Embed(
413
  title="⏱️ Bot Uptime",
414
  description=get_uptime(),
415
  color=discord.Color.blue()
416
  )
417
- await ctx.send(embed=embed)
418
 
419
- # Error Handler
420
- @bot.event
421
- async def on_command_error(ctx, error):
422
- if isinstance(error, commands.CommandNotFound):
423
- return # Ignore unknown commands
424
-
425
- elif isinstance(error, commands.MissingRequiredArgument):
426
- embed = discord.Embed(
427
- title="❌ Missing Argument",
428
- description=f"Missing required argument: `{error.param.name}`\nUse `!help {ctx.command.name}` for usage info.",
429
- color=discord.Color.red()
430
- )
431
- await ctx.send(embed=embed)
432
-
433
- elif isinstance(error, commands.MissingPermissions):
434
  embed = discord.Embed(
435
  title="❌ Missing Permissions",
436
  description=f"You need `{', '.join(error.missing_permissions)}` permission to use this command.",
437
  color=discord.Color.red()
438
  )
439
- await ctx.send(embed=embed)
 
 
 
440
 
441
- elif isinstance(error, commands.MemberNotFound):
442
  embed = discord.Embed(
443
- title="❌ User Not Found",
444
- description="The specified user was not found.",
445
  color=discord.Color.red()
446
  )
447
- await ctx.send(embed=embed)
 
 
 
448
 
449
  else:
450
- logger.error(f"Command error: {error}")
451
  embed = discord.Embed(
452
  title="❌ Error",
453
  description="An unexpected error occurred. Please try again later.",
454
  color=discord.Color.red()
455
  )
456
- await ctx.send(embed=embed)
 
 
 
457
 
458
  # Helper function: Get uptime
459
  start_time = datetime.now()
 
1
  import discord
2
  from discord.ext import commands, tasks
3
+ from discord import app_commands
4
  import os
5
  import asyncio
6
  from datetime import datetime
7
  import logging
8
  from flask import Flask
9
  from threading import Thread
10
+ import random
11
 
12
  # Setup logging
13
  logging.basicConfig(
 
24
  return "hey, bot started✅"
25
 
26
  def run_web():
27
+ app.run(host='0.0.0.0', port=3000)
28
 
29
  # Start web server in a thread
30
  web_thread = Thread(target=run_web)
 
37
 
38
  # Bot intents
39
  intents = discord.Intents.default()
40
+ intents.message_content = True
41
  intents.members = True
42
  intents.presences = True
43
 
44
+ # Create bot instance - NO prefix needed for slash commands
45
  bot = commands.Bot(
46
+ command_prefix=None,
47
  intents=intents,
48
+ help_command=None,
49
  case_insensitive=True
50
  )
51
 
 
55
  logger.info(f'✅ Bot logged in as {bot.user.name} ({bot.user.id})')
56
  logger.info(f'🌐 Connected to {len(bot.guilds)} guilds')
57
 
58
+ # Sync slash commands globally
59
+ try:
60
+ synced = await bot.tree.sync()
61
+ logger.info(f'✅ Synced {len(synced)} slash commands globally')
62
+ except Exception as e:
63
+ logger.error(f'❌ Failed to sync commands: {e}')
64
+
65
  # Set bot status
66
  await bot.change_presence(
67
  activity=discord.Activity(
68
  type=discord.ActivityType.watching,
69
+ name=f"{len(bot.guilds)} servers | /help"
70
  ),
71
  status=discord.Status.online
72
  )
 
80
  await bot.change_presence(
81
  activity=discord.Activity(
82
  type=discord.ActivityType.watching,
83
+ name=f"{len(bot.guilds)} servers | /help"
84
  ),
85
  status=discord.Status.online
86
  )
 
95
  async def on_guild_remove(guild):
96
  logger.info(f'➖ Left guild: {guild.name} ({guild.id})')
97
 
98
+ # ==================== SLASH COMMANDS ====================
99
+
100
+ # Help Command - Shows all commands in chat with autocomplete
101
+ @bot.tree.command(name="help", description="Show all available commands")
102
+ @app_commands.describe(command_name="Specific command to get help for")
103
+ @app_commands.choices(command_name=[
104
+ app_commands.Choice(name="help", value="help"),
105
+ app_commands.Choice(name="ping", value="ping"),
106
+ app_commands.Choice(name="info", value="info"),
107
+ app_commands.Choice(name="serverinfo", value="serverinfo"),
108
+ app_commands.Choice(name="userinfo", value="userinfo"),
109
+ app_commands.Choice(name="avatar", value="avatar"),
110
+ app_commands.Choice(name="say", value="say"),
111
+ app_commands.Choice(name="embed", value="embed"),
112
+ app_commands.Choice(name="poll", value="poll"),
113
+ app_commands.Choice(name="8ball", value="8ball"),
114
+ app_commands.Choice(name="coinflip", value="coinflip"),
115
+ app_commands.Choice(name="invite", value="invite"),
116
+ app_commands.Choice(name="clear", value="clear"),
117
+ app_commands.Choice(name="uptime", value="uptime"),
118
+ ])
119
+ async def help_command(interaction: discord.Interaction, command_name: str = None):
120
  """Show help information"""
121
  if command_name:
122
  # Show specific command help
123
+ command_details = {
124
+ "help": {
125
+ "description": "Show all available commands or specific command help",
126
+ "usage": "/help [command_name]",
127
+ "examples": ["/help", "/help ping"]
128
+ },
129
+ "ping": {
130
+ "description": "Check bot latency and API response time",
131
+ "usage": "/ping",
132
+ "examples": ["/ping"]
133
+ },
134
+ "info": {
135
+ "description": "Show bot information and statistics",
136
+ "usage": "/info",
137
+ "examples": ["/info"]
138
+ },
139
+ "serverinfo": {
140
+ "description": "Show server information",
141
+ "usage": "/serverinfo",
142
+ "examples": ["/serverinfo"]
143
+ },
144
+ "userinfo": {
145
+ "description": "Show user information",
146
+ "usage": "/userinfo [member]",
147
+ "examples": ["/userinfo", "/userinfo @user"]
148
+ },
149
+ "avatar": {
150
+ "description": "Show user's avatar in full size",
151
+ "usage": "/avatar [member]",
152
+ "examples": ["/avatar", "/avatar @user"]
153
+ },
154
+ "say": {
155
+ "description": "Make the bot say something",
156
+ "usage": "/say <message>",
157
+ "examples": ["/say Hello everyone!"]
158
+ },
159
+ "embed": {
160
+ "description": "Create a custom embed message",
161
+ "usage": "/embed <message>",
162
+ "examples": ["/embed This is a custom embed"]
163
+ },
164
+ "poll": {
165
+ "description": "Create a poll with 👍 👎 🤷 reactions",
166
+ "usage": "/poll <question>",
167
+ "examples": ["/poll Should we add more channels?"]
168
+ },
169
+ "8ball": {
170
+ "description": "Ask the magic 8-ball a question",
171
+ "usage": "/8ball <question>",
172
+ "examples": ["/8ball Will I win the lottery?"]
173
+ },
174
+ "coinflip": {
175
+ "description": "Flip a coin (Heads or Tails)",
176
+ "usage": "/coinflip",
177
+ "examples": ["/coinflip"]
178
+ },
179
+ "invite": {
180
+ "description": "Get bot invite link",
181
+ "usage": "/invite",
182
+ "examples": ["/invite"]
183
+ },
184
+ "clear": {
185
+ "description": "Clear messages (requires Manage Messages permission)",
186
+ "usage": "/clear <amount>",
187
+ "examples": ["/clear 10"]
188
+ },
189
+ "uptime": {
190
+ "description": "Show bot uptime",
191
+ "usage": "/uptime",
192
+ "examples": ["/uptime"]
193
+ }
194
+ }
195
+
196
+ if command_name in command_details:
197
+ details = command_details[command_name]
198
  embed = discord.Embed(
199
+ title=f"📖 Help: /{command_name}",
200
+ description=details["description"],
201
  color=discord.Color.blue()
202
  )
203
+ embed.add_field(name="Usage", value=f"`{details['usage']}`", inline=False)
204
+ embed.add_field(name="Examples", value="\n".join([f"`{ex}`" for ex in details["examples"]]), inline=False)
205
+ await interaction.response.send_message(embed=embed)
 
 
 
 
 
 
 
 
 
206
  else:
207
+ await interaction.response.send_message(f"❌ Command `/{command_name}` not found!", ephemeral=True)
208
  else:
209
+ # Show all commands in chat
210
  embed = discord.Embed(
211
  title="🤖 Bot Commands",
212
+ description="Here are all available slash commands:",
213
  color=discord.Color.blue(),
214
  timestamp=datetime.now()
215
  )
216
 
217
  # Categorize commands
218
  categories = {
219
+ "📁 General": [
220
+ "`/help` - Show commands",
221
+ "`/ping` - Check latency",
222
+ "`/info` - Bot info",
223
+ "`/serverinfo` - Server info",
224
+ "`/userinfo` - User info",
225
+ "`/uptime` - Bot uptime"
226
+ ],
227
+ "🎉 Fun": [
228
+ "`/say` - Bot says something",
229
+ "`/embed` - Custom embed",
230
+ "`/poll` - Create poll",
231
+ "`/8ball` - Magic 8-ball",
232
+ "`/coinflip` - Flip a coin"
233
+ ],
234
+ "🛠️ Utility": [
235
+ "`/avatar` - Show avatar",
236
+ "`/invite` - Bot invite link",
237
+ "`/clear` - Clear messages"
238
+ ]
239
  }
240
 
241
  for category, cmds in categories.items():
242
+ embed.add_field(
243
+ name=category,
244
+ value="\n".join(cmds),
245
+ inline=False
246
+ )
 
 
 
 
 
 
247
 
248
+ embed.set_footer(text="Use /help <command> for more details")
249
+ await interaction.response.send_message(embed=embed)
250
 
251
  # Ping Command
252
+ @bot.tree.command(name="ping", description="Check bot latency")
253
+ async def ping_command(interaction: discord.Interaction):
254
  """Check bot latency"""
255
  latency = round(bot.latency * 1000)
256
 
257
+ color = discord.Color.green() if latency < 200 else discord.Color.orange() if latency < 500 else discord.Color.red()
258
+
259
  embed = discord.Embed(
260
  title="🏓 Pong!",
261
  description=f"**Latency:** `{latency}ms`\n**API Latency:** `{round(bot.latency * 1000)}ms`",
262
+ color=color
263
  )
264
+ embed.set_footer(text=f"Requested by {interaction.user.name}")
265
+ await interaction.response.send_message(embed=embed)
266
 
267
  # Info Command
268
+ @bot.tree.command(name="info", description="Show bot information")
269
+ async def info_command(interaction: discord.Interaction):
270
  """Show bot information"""
271
  embed = discord.Embed(
272
  title="🤖 Bot Information",
 
287
  embed.set_thumbnail(url=bot.user.avatar.url if bot.user.avatar else bot.user.default_avatar.url)
288
  embed.set_footer(text="Made with ❤️ using discord.py")
289
 
290
+ await interaction.response.send_message(embed=embed)
291
 
292
  # Server Info Command
293
+ @bot.tree.command(name="serverinfo", description="Show server information")
294
+ async def serverinfo_command(interaction: discord.Interaction):
295
  """Show server information"""
296
+ guild = interaction.guild
297
 
298
  embed = discord.Embed(
299
  title=f"📊 {guild.name} Server Info",
 
312
  if guild.icon:
313
  embed.set_thumbnail(url=guild.icon.url)
314
 
315
+ await interaction.response.send_message(embed=embed)
316
 
317
  # User Info Command
318
+ @bot.tree.command(name="userinfo", description="Show user information")
319
+ @app_commands.describe(member="User to get info about (default: you)")
320
+ async def userinfo_command(interaction: discord.Interaction, member: discord.Member = None):
321
  """Show user information"""
322
+ member = member or interaction.user
323
 
324
  embed = discord.Embed(
325
  title=f"👤 {member.name}'s Profile",
 
336
  embed.add_field(name="Top Role", value=member.top_role.mention, inline=True)
337
  embed.add_field(name="Bot?", value="Yes" if member.bot else "No", inline=True)
338
 
339
+ roles = [role.mention for role in member.roles if role != interaction.guild.default_role]
340
  if roles:
341
  embed.add_field(name=f"Roles ({len(roles)})", value=" ".join(roles[:10]) + ("..." if len(roles) > 10 else ""), inline=False)
342
 
343
  embed.set_thumbnail(url=member.avatar.url if member.avatar else member.default_avatar.url)
344
+ embed.set_footer(text=f"Requested by {interaction.user.name}")
345
 
346
+ await interaction.response.send_message(embed=embed)
347
 
348
  # Avatar Command
349
+ @bot.tree.command(name="avatar", description="Show user's avatar")
350
+ @app_commands.describe(member="User to show avatar (default: you)")
351
+ async def avatar_command(interaction: discord.Interaction, member: discord.Member = None):
352
  """Show user's avatar"""
353
+ member = member or interaction.user
354
 
355
  embed = discord.Embed(
356
  title=f"🖼️ {member.name}'s Avatar",
 
359
 
360
  avatar_url = member.avatar.url if member.avatar else member.default_avatar.url
361
  embed.set_image(url=avatar_url)
362
+ embed.add_field(name="Links", value=f"[PNG]({avatar_url}) | [WEBP]({avatar_url})", inline=False)
363
 
364
+ await interaction.response.send_message(embed=embed)
365
 
366
  # Say Command
367
+ @bot.tree.command(name="say", description="Make the bot say something")
368
+ @app_commands.describe(message="Message to say")
369
+ async def say_command(interaction: discord.Interaction, message: str):
370
  """Make the bot say something"""
371
+ await interaction.response.send_message(message)
 
372
 
373
  # Embed Command
374
+ @bot.tree.command(name="embed", description="Create a custom embed")
375
+ @app_commands.describe(message="Message for the embed")
376
+ async def embed_command(interaction: discord.Interaction, message: str):
377
  """Create a custom embed"""
378
  embed = discord.Embed(
379
  description=message,
380
  color=discord.Color.blue(),
381
  timestamp=datetime.now()
382
  )
383
+ embed.set_author(name=interaction.user.name, icon_url=interaction.user.avatar.url if interaction.user.avatar else interaction.user.default_avatar.url)
384
+ await interaction.response.send_message(embed=embed)
385
 
386
  # Poll Command
387
+ @bot.tree.command(name="poll", description="Create a poll")
388
+ @app_commands.describe(question="Poll question")
389
+ async def poll_command(interaction: discord.Interaction, question: str):
390
  """Create a poll"""
391
  embed = discord.Embed(
392
  title="📊 Poll",
 
394
  color=discord.Color.blue(),
395
  timestamp=datetime.now()
396
  )
397
+ embed.set_footer(text=f"Poll by {interaction.user.name}")
398
 
399
+ await interaction.response.send_message(embed=embed)
400
+ poll_message = await interaction.original_response()
401
  await poll_message.add_reaction("👍")
402
  await poll_message.add_reaction("👎")
403
  await poll_message.add_reaction("🤷")
404
 
405
  # 8Ball Command
406
+ @bot.tree.command(name="8ball", description="Ask the magic 8-ball")
407
+ @app_commands.describe(question="Your question")
408
+ async def eightball_command(interaction: discord.Interaction, question: str):
409
  """Ask the magic 8-ball"""
 
 
410
  responses = [
411
  "🎱 It is certain.",
412
  "🎱 It is decidedly so.",
 
437
  embed.add_field(name="Question", value=question, inline=False)
438
  embed.add_field(name="Answer", value=random.choice(responses), inline=False)
439
 
440
+ await interaction.response.send_message(embed=embed)
441
 
442
  # Coin Flip Command
443
+ @bot.tree.command(name="coinflip", description="Flip a coin")
444
+ async def coinflip_command(interaction: discord.Interaction):
445
  """Flip a coin"""
 
 
446
  result = random.choice(["Heads", "Tails"])
 
447
 
448
  embed = discord.Embed(
449
+ title=f"🪙 Coin Flip",
450
  description=f"**Result:** {result}",
451
  color=discord.Color.gold()
452
  )
453
 
454
+ await interaction.response.send_message(embed=embed)
455
 
456
  # Invite Command
457
+ @bot.tree.command(name="invite", description="Get bot invite link")
458
+ async def invite_command(interaction: discord.Interaction):
459
  """Get bot invite link"""
460
  permissions = discord.Permissions(
461
  send_messages=True,
 
479
  )
480
  embed.add_field(name="Bot ID", value=bot.user.id, inline=False)
481
 
482
+ await interaction.response.send_message(embed=embed)
483
 
484
  # Clear Command
485
+ @bot.tree.command(name="clear", description="Clear messages")
486
+ @app_commands.describe(amount="Number of messages to clear (1-100)")
487
+ @app_commands.checks.has_permissions(manage_messages=True)
488
+ async def clear_command(interaction: discord.Interaction, amount: int):
489
  """Clear messages (requires Manage Messages permission)"""
490
  if amount < 1 or amount > 100:
491
+ await interaction.response.send_message("❌ Please specify a number between 1 and 100!", ephemeral=True)
492
  return
493
 
494
+ await interaction.response.defer(ephemeral=True)
495
+ deleted = await interaction.channel.purge(limit=amount)
496
  embed = discord.Embed(
497
+ description=f"🗑️ Deleted {len(deleted)} messages!",
498
  color=discord.Color.green()
499
  )
500
+ await interaction.followup.send(embed=embed, ephemeral=True)
501
  await asyncio.sleep(3)
502
+ try:
503
+ await interaction.delete_original_response()
504
+ except:
505
+ pass
506
 
507
  # Uptime Command
508
+ @bot.tree.command(name="uptime", description="Show bot uptime")
509
+ async def uptime_command(interaction: discord.Interaction):
510
  """Show bot uptime"""
511
  embed = discord.Embed(
512
  title="⏱️ Bot Uptime",
513
  description=get_uptime(),
514
  color=discord.Color.blue()
515
  )
516
+ await interaction.response.send_message(embed=embed)
517
 
518
+ # Error Handler for Slash Commands
519
+ @bot.tree.error
520
+ async def on_app_command_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
521
+ if isinstance(error, app_commands.MissingPermissions):
 
 
 
 
 
 
 
 
 
 
 
522
  embed = discord.Embed(
523
  title="❌ Missing Permissions",
524
  description=f"You need `{', '.join(error.missing_permissions)}` permission to use this command.",
525
  color=discord.Color.red()
526
  )
527
+ if interaction.response.is_done():
528
+ await interaction.followup.send(embed=embed, ephemeral=True)
529
+ else:
530
+ await interaction.response.send_message(embed=embed, ephemeral=True)
531
 
532
+ elif isinstance(error, app_commands.CheckFailure):
533
  embed = discord.Embed(
534
+ title="❌ Check Failed",
535
+ description="You do not have permission to use this command.",
536
  color=discord.Color.red()
537
  )
538
+ if interaction.response.is_done():
539
+ await interaction.followup.send(embed=embed, ephemeral=True)
540
+ else:
541
+ await interaction.response.send_message(embed=embed, ephemeral=True)
542
 
543
  else:
544
+ logger.error(f"Slash command error: {error}")
545
  embed = discord.Embed(
546
  title="❌ Error",
547
  description="An unexpected error occurred. Please try again later.",
548
  color=discord.Color.red()
549
  )
550
+ if interaction.response.is_done():
551
+ await interaction.followup.send(embed=embed, ephemeral=True)
552
+ else:
553
+ await interaction.response.send_message(embed=embed, ephemeral=True)
554
 
555
  # Helper function: Get uptime
556
  start_time = datetime.now()