Why is the background in Tasca discord.py not working?

Hi guys
who worked with the library discord.py
Tell me, please, why the background Tasca may not be executed
The odd file is empty at all :(
Here is a link to the code
Where to look?where to dig?I would appreciate any advice
April 19th 20 at 12:11
1 answer
April 19th 20 at 12:13
Solution
Maybe because the loop is not running?
import shell
import re
from tinydb import TinyDB, the Query
import asyncio
from discord.ext import commands


my_background_task def async():
 await client.wait_until_ready()
 while not client.is_closed:
 with open("stats.txt", "a") as f:
f.write("Hello\n")
 await asyncio.sleep(5) # task runs every 60 seconds



class MyClient(ex.Client):
 async def on_ready(self):
 print("Logged as {0}!".format(self.user))

 def recognize(self, test_str):
 regex = r"--(\w+)=([^--]+)"
 matches = re.findall(regex, test_str)
 return matches

 async def on_message(self, message):
 # print('699352136273887292' == str(message.guild.id))
 # print('699352136273887292' + '|| ' + str(message.guild.id))
 print("Message from {0.author}: {0.content}".format(message))
 text = message.content.lower()
 if "!send" in text and message.author.bot is False:
 b = client.get_guild(699352136273887292)
 users = []
 for member in b.members:
 user = client.get_user(member.id)
 if user.bot:
continue
users.append(str(member.id))
print(users)
 params = {'users': ','.join(users)}
 recognize_objects = self.recognize(text)
 for object in recognize_objects:
 params[object[0].strip()] = object[1].strip()
 db = TinyDB('db.json')
db.insert(params)


client = MyClient()
client.loop.create_task(my_background_task)
client.loop.run_forever()
https://pastebin.com/CzDLcirN thank you so much for the solution - Winnifred commented on April 19th 20 at 12:16

Find more questions by tags Python