wpms commited on
Commit
da3b96b
·
verified ·
1 Parent(s): 5af21cf

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +33 -13
main.py CHANGED
@@ -6,7 +6,6 @@ from datetime import datetime
6
  import logging
7
  from flask import Flask
8
  from threading import Thread
9
- import aiohttp
10
 
11
  # Setup logging
12
  logging.basicConfig(
@@ -23,7 +22,7 @@ def home():
23
  return "hey, bot started✅"
24
 
25
  def run_web():
26
- app.run(host='0.0.0.0', port=7860)
27
 
28
  # Start web server in a thread
29
  web_thread = Thread(target=run_web)
@@ -36,31 +35,25 @@ if not TOKEN:
36
 
37
  # Bot intents
38
  intents = discord.Intents.default()
39
- intents.message_content = True
40
  intents.members = True
41
  intents.presences = True
42
 
43
- # Create bot instance with proxy support
44
  bot = commands.Bot(
45
  command_prefix='!',
46
  intents=intents,
47
- help_command=None,
48
  case_insensitive=True
49
  )
50
 
51
- # Set up proxy for Discord connection (if behind firewall)
52
- async def setup_proxy():
53
- proxy = os.getenv('HTTP_PROXY') or os.getenv('HTTPS_PROXY')
54
- if proxy:
55
- bot.http.proxy = proxy
56
- logger.info(f"Using proxy: {proxy}")
57
-
58
  # Event: Bot ready
59
  @bot.event
60
  async def on_ready():
61
  logger.info(f'✅ Bot logged in as {bot.user.name} ({bot.user.id})')
62
  logger.info(f'🌐 Connected to {len(bot.guilds)} guilds')
63
 
 
64
  await bot.change_presence(
65
  activity=discord.Activity(
66
  type=discord.ActivityType.watching,
@@ -69,8 +62,10 @@ async def on_ready():
69
  status=discord.Status.online
70
  )
71
 
 
72
  status_update.start()
73
 
 
74
  @tasks.loop(minutes=5)
75
  async def status_update():
76
  await bot.change_presence(
@@ -81,26 +76,34 @@ async def status_update():
81
  status=discord.Status.online
82
  )
83
 
 
84
  @bot.event
85
  async def on_guild_join(guild):
86
  logger.info(f'➕ Joined guild: {guild.name} ({guild.id})')
87
 
 
88
  @bot.event
89
  async def on_guild_remove(guild):
90
  logger.info(f'➖ Left guild: {guild.name} ({guild.id})')
91
 
 
92
  @bot.event
93
  async def on_message(message):
 
94
  if message.author.bot:
95
  return
 
 
96
  await bot.process_commands(message)
97
 
98
  # ==================== COMMANDS ====================
99
 
 
100
  @bot.command(name='help', aliases=['h', 'commands'])
101
  async def help_command(ctx, command_name: str = None):
102
  """Show help information"""
103
  if command_name:
 
104
  command = bot.get_command(command_name)
105
  if command:
106
  embed = discord.Embed(
@@ -123,6 +126,7 @@ async def help_command(ctx, command_name: str = None):
123
  else:
124
  await ctx.send(f"❌ Command `!{command_name}` not found!")
125
  else:
 
126
  embed = discord.Embed(
127
  title="🤖 Bot Commands",
128
  description="Here are all available commands:",
@@ -130,6 +134,7 @@ async def help_command(ctx, command_name: str = None):
130
  timestamp=datetime.now()
131
  )
132
 
 
133
  categories = {
134
  "General": ['help', 'ping', 'info', 'serverinfo', 'userinfo'],
135
  "Fun": ['say', 'embed', 'poll', '8ball', 'coinflip'],
@@ -152,6 +157,7 @@ async def help_command(ctx, command_name: str = None):
152
  embed.set_footer(text=f"Use !help <command> for more details | Prefix: !")
153
  await ctx.send(embed=embed)
154
 
 
155
  @bot.command(name='ping', aliases=['latency'])
156
  async def ping_command(ctx):
157
  """Check bot latency"""
@@ -165,6 +171,7 @@ async def ping_command(ctx):
165
  embed.set_footer(text=f"Requested by {ctx.author.name}")
166
  await ctx.send(embed=embed)
167
 
 
168
  @bot.command(name='info', aliases=['botinfo', 'about'])
169
  async def info_command(ctx):
170
  """Show bot information"""
@@ -189,6 +196,7 @@ async def info_command(ctx):
189
 
190
  await ctx.send(embed=embed)
191
 
 
192
  @bot.command(name='serverinfo', aliases=['server', 'guildinfo'])
193
  async def serverinfo_command(ctx):
194
  """Show server information"""
@@ -213,6 +221,7 @@ async def serverinfo_command(ctx):
213
 
214
  await ctx.send(embed=embed)
215
 
 
216
  @bot.command(name='userinfo', aliases=['whois', 'profile'])
217
  async def userinfo_command(ctx, member: discord.Member = None):
218
  """Show user information"""
@@ -242,6 +251,7 @@ async def userinfo_command(ctx, member: discord.Member = None):
242
 
243
  await ctx.send(embed=embed)
244
 
 
245
  @bot.command(name='avatar', aliases=['av', 'pfp'])
246
  async def avatar_command(ctx, member: discord.Member = None):
247
  """Show user's avatar"""
@@ -258,12 +268,14 @@ async def avatar_command(ctx, member: discord.Member = None):
258
 
259
  await ctx.send(embed=embed)
260
 
 
261
  @bot.command(name='say', aliases=['echo'])
262
  async def say_command(ctx, *, message: str):
263
  """Make the bot say something"""
264
  await ctx.message.delete()
265
  await ctx.send(message)
266
 
 
267
  @bot.command(name='embed', aliases=['em'])
268
  async def embed_command(ctx, *, message: str):
269
  """Create a custom embed"""
@@ -275,6 +287,7 @@ async def embed_command(ctx, *, message: str):
275
  embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url if ctx.author.avatar else ctx.author.default_avatar.url)
276
  await ctx.send(embed=embed)
277
 
 
278
  @bot.command(name='poll', aliases=['vote'])
279
  async def poll_command(ctx, *, question: str):
280
  """Create a poll"""
@@ -291,6 +304,7 @@ async def poll_command(ctx, *, question: str):
291
  await poll_message.add_reaction("👎")
292
  await poll_message.add_reaction("🤷")
293
 
 
294
  @bot.command(name='8ball', aliases=['magic8ball', 'ask'])
295
  async def eightball_command(ctx, *, question: str):
296
  """Ask the magic 8-ball"""
@@ -328,6 +342,7 @@ async def eightball_command(ctx, *, question: str):
328
 
329
  await ctx.send(embed=embed)
330
 
 
331
  @bot.command(name='coinflip', aliases=['flip', 'coin'])
332
  async def coinflip_command(ctx):
333
  """Flip a coin"""
@@ -344,6 +359,7 @@ async def coinflip_command(ctx):
344
 
345
  await ctx.send(embed=embed)
346
 
 
347
  @bot.command(name='invite', aliases=['addbot'])
348
  async def invite_command(ctx):
349
  """Get bot invite link"""
@@ -371,6 +387,7 @@ async def invite_command(ctx):
371
 
372
  await ctx.send(embed=embed)
373
 
 
374
  @bot.command(name='clear', aliases=['purge', 'clean'])
375
  @commands.has_permissions(manage_messages=True)
376
  async def clear_command(ctx, amount: int = 5):
@@ -388,6 +405,7 @@ async def clear_command(ctx, amount: int = 5):
388
  await asyncio.sleep(3)
389
  await msg.delete()
390
 
 
391
  @bot.command(name='uptime', aliases=['up'])
392
  async def uptime_command(ctx):
393
  """Show bot uptime"""
@@ -398,10 +416,11 @@ async def uptime_command(ctx):
398
  )
399
  await ctx.send(embed=embed)
400
 
 
401
  @bot.event
402
  async def on_command_error(ctx, error):
403
  if isinstance(error, commands.CommandNotFound):
404
- return
405
 
406
  elif isinstance(error, commands.MissingRequiredArgument):
407
  embed = discord.Embed(
@@ -436,6 +455,7 @@ async def on_command_error(ctx, error):
436
  )
437
  await ctx.send(embed=embed)
438
 
 
439
  start_time = datetime.now()
440
 
441
  def get_uptime():
 
6
  import logging
7
  from flask import Flask
8
  from threading import Thread
 
9
 
10
  # Setup logging
11
  logging.basicConfig(
 
22
  return "hey, bot started✅"
23
 
24
  def run_web():
25
+ app.run(host='0.0.0.0', port=3000)
26
 
27
  # Start web server in a thread
28
  web_thread = Thread(target=run_web)
 
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
 
 
 
 
 
 
 
 
50
  # Event: Bot ready
51
  @bot.event
52
  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,
 
62
  status=discord.Status.online
63
  )
64
 
65
+ # Start background tasks
66
  status_update.start()
67
 
68
+ # Background task: Update status every 5 minutes
69
  @tasks.loop(minutes=5)
70
  async def status_update():
71
  await bot.change_presence(
 
76
  status=discord.Status.online
77
  )
78
 
79
+ # Event: When bot joins a new guild
80
  @bot.event
81
  async def on_guild_join(guild):
82
  logger.info(f'➕ Joined guild: {guild.name} ({guild.id})')
83
 
84
+ # Event: When bot leaves a guild
85
  @bot.event
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(
 
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:",
 
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'],
 
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"""
 
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"""
 
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"""
 
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"""
 
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"""
 
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"""
 
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"""
 
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"""
 
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"""
 
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"""
 
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):
 
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"""
 
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(
 
455
  )
456
  await ctx.send(embed=embed)
457
 
458
+ # Helper function: Get uptime
459
  start_time = datetime.now()
460
 
461
  def get_uptime():