enhanced-discord.py/examples/background_task.py
Modelmat 1436af3b18 Removes redundant asyncio import
Not much point importing asyncio when it's not being used, it was there for when @asyncio.coroutine was used previously
2018-08-22 21:06:09 -04:00

28 lines
787 B
Python

import discord
class MyClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# create the background task and run it in the background
self.bg_task = self.loop.create_task(self.my_background_task())
async def on_ready(self):
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
async def my_background_task(self):
await self.wait_until_ready()
counter = 0
channel = self.get_channel(1234567) # channel ID goes here
while not self.is_closed():
counter += 1
await channel.send(counter)
await asyncio.sleep(60) # task runs every 60 seconds
client = MyClient()
client.run('token')