I'm trying to send a message with discord, activated through a Flask endpoint
I get the following error message when I call http://127.0.0.1:5000/send
RuntimeError: There is no current event loop in thread 'Thread-4'.
I have the following (minimal) code
import discord
from flask import Flask, jsonify
async def my_background_task():
for message in ['a', 'b']:
await client.wait_until_ready()
channel = client.get_channel(CHANNEL_ID)
await channel.send(message)
await client.close()
def sendMessages():
client = discord.Client()
client.loop.create_task(my_background_task())
client.run('SECRET')
app = Flask(__name__)
@app.route('/send')
def send():
sendMessages()