Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import re
- from tinydb import TinyDB
- import asyncio
- async def my_background_task():
- print("Started!")
- await client.wait_until_ready()
- while client.is_closed:
- with open("stats.txt", "a") as f:
- f.write("Hello\n")
- print("Wrote!")
- 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("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 obj in recognize_objects:
- params[obj[0].strip()] = obj[1].strip()
- db = TinyDB('db.json')
- db.insert(params)
- client = MyClient()
- client.loop.create_task(my_background_task())
- client.run('token')
Add Comment
Please, Sign In to add comment