Probably I’m starting with the wrong foot in python due to not the best pattern approach. I have a script to run a discord bot and a flask api. I instantiate the bot and all the synchronous routes work properly.
Then, i have a function that makes the bot read the first message in a channel and send it through the API.
Class myBot():
def __init__ (self):
self.botInstance = self
def run_bot(self) #used on main.py, to start the bot
client = discord.Client(intents=intents)
self.client = client
@client.event
async def on_ready():
loop = asyncio.get_event_loop()
self.loop = loop
async def get_first_message(self):
channel = self.client.get_channel(XXXXXXXX) #mychannelid
loop = asyncio.get_running_loop()
async for message in loop.run_until_complete(channel.history(limit=1, oldest_first=True)):
return message.content
I tried multiple approaches, but either i get TypeError: An asyncio.Future, a coroutine or an awaitable is required
or RuntimeError: Timeout context manager should be used inside a task
.
And yes, I’ve checked the documentation, i’m just too green with python to debug the situation.