abhicodes commited on
Commit
f5f83f5
·
1 Parent(s): 92a9890

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +9 -28
bot.py CHANGED
@@ -2,9 +2,6 @@ import discord
2
  from discord.ext import commands
3
  import mysql.connector
4
  import os
5
- from flask import Flask
6
-
7
- app = Flask(__name__)
8
 
9
  mysql = mysql.connector.connect(
10
  host=os.environ.get('DB_HOST'),
@@ -13,24 +10,25 @@ mysql = mysql.connector.connect(
13
  database=os.environ.get('DB_DATABASE'),
14
  port=3306
15
  )
 
16
  intents = discord.Intents.default()
17
  intents.message_content = True
18
- bot = commands.Bot(command_prefix='!', intents=intents)
19
 
20
 
21
- @bot.event
22
  async def on_ready():
23
- print(f'{bot.user} is now running!')
24
 
25
 
26
- @bot.event
27
  async def on_message(message):
28
- if message.author == bot.user:
29
  return
30
 
31
  server_name = message.author.guild.name
32
 
33
- if bot.user.mentioned_in(message):
34
  await send_message(message, server_name)
35
 
36
 
@@ -41,13 +39,7 @@ async def send_message(message, server_name):
41
  print(e)
42
 
43
 
44
- # Flask route for health check or any other purposes
45
- @app.route('/')
46
- def home():
47
- return "Discord Bot is running!"
48
-
49
-
50
- def run_discord_bot():
51
  cursor = mysql.cursor(dictionary=True)
52
  cursor.execute("SELECT `token` FROM `auth_tokens` WHERE bot_id=%s", ((os.environ.get('BOT_ID')),))
53
  bot_token = cursor.fetchone()
@@ -55,15 +47,4 @@ def run_discord_bot():
55
 
56
  TOKEN = bot_token['token']
57
 
58
- bot.run(TOKEN)
59
-
60
-
61
- if __name__ == '__main__':
62
- # Run the Flask application alongside the Discord bot
63
- from gevent.pywsgi import WSGIServer
64
-
65
- server = WSGIServer(('0.0.0.0', 5000), app)
66
- server.start()
67
-
68
- # Run the Discord bot
69
- run_discord_bot()
 
2
  from discord.ext import commands
3
  import mysql.connector
4
  import os
 
 
 
5
 
6
  mysql = mysql.connector.connect(
7
  host=os.environ.get('DB_HOST'),
 
10
  database=os.environ.get('DB_DATABASE'),
11
  port=3306
12
  )
13
+
14
  intents = discord.Intents.default()
15
  intents.message_content = True
16
+ app = discord.Client(intents=intents)
17
 
18
 
19
+ @app.event
20
  async def on_ready():
21
+ print(f'{app.user} is now running!')
22
 
23
 
24
+ @app.event
25
  async def on_message(message):
26
+ if message.author == app.user:
27
  return
28
 
29
  server_name = message.author.guild.name
30
 
31
+ if app.user.mentioned_in(message):
32
  await send_message(message, server_name)
33
 
34
 
 
39
  print(e)
40
 
41
 
42
+ if __name__ == '__main__':
 
 
 
 
 
 
43
  cursor = mysql.cursor(dictionary=True)
44
  cursor.execute("SELECT `token` FROM `auth_tokens` WHERE bot_id=%s", ((os.environ.get('BOT_ID')),))
45
  bot_token = cursor.fetchone()
 
47
 
48
  TOKEN = bot_token['token']
49
 
50
+ app.run(TOKEN)