Может потому что
loop не запущен?
import discord
import re
from tinydb import TinyDB, Query
import asyncio
from discord.ext import commands
async def my_background_task():
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(discord.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 "!разослать" 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()