I am trying to create a discord bot with two features.
- To update everyone in the server about some info (this is done by using webhook and a uptimerobot to call the webhook)
- Community in the server can prompt the bot to provide additional info by telling the bot the ID of.
I am using app.route for the first feature and on_message() as the second one. But only the first one is working.
This is the snippet of my code
import discord
import asyncio
import os
from quart import Quart
from discord.ext import commands
from dotenv import load_dotenv
import requests
import datetime
from datetime import timezone
import json
import random
import nest_asyncio
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
OS_TOKEN = os.getenv('OPENSEA_TOKEN')
nest_asyncio.apply()
app = Quart(__name__)
client = discord.Client()
@app.before_serving
async def before_serving():
loop = asyncio.get_event_loop()
await client.login(TOKEN)
loop.create_task(client.connect())
@client.event
async def on_message(message):
if message.author == client.user:
return
print('in func')
@client.event
async def on_ready():
print("Initiated!")
@app.route("/send")
async def broadcast():
for server in client.guilds:
for channel in server.text_channels:
try:
await channel.send("test")
except Exception:
continue
else:
break
return "hello world"
app.run()
I managed to run both separately. But when I run them together, only the webhook is working and any @client modules are not working. Also I migrated from flask to quart because I read somewhere that flask can not run both itself and discord server.
Any help would be appreciated!