0

I am trying to create a discord bot with two features.

  1. To update everyone in the server about some info (this is done by using webhook and a uptimerobot to call the webhook)
  2. 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!

Ace Edith
  • 11
  • 3

1 Answers1

0

I think u might have forgotten to check the needed permissions in the discord dev portal. and also I solved my somehow similar problem by replacing @client.event(s) with @bot.event

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 05 '22 at 01:51