Spaces:
Paused
Paused
Update bot.py
Browse files
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 |
-
|
19 |
|
20 |
|
21 |
-
@
|
22 |
async def on_ready():
|
23 |
-
print(f'{
|
24 |
|
25 |
|
26 |
-
@
|
27 |
async def on_message(message):
|
28 |
-
if message.author ==
|
29 |
return
|
30 |
|
31 |
server_name = message.author.guild.name
|
32 |
|
33 |
-
if
|
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 |
-
|
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 |
-
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|