add the apscheduler
This commit is contained in:
parent
bc2796492a
commit
fcdef2e17c
1 changed files with 23 additions and 1 deletions
|
@ -1,15 +1,22 @@
|
|||
import asyncio
|
||||
import os
|
||||
import discord
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
# Read env variables
|
||||
bot_token = os.environ.get('DISCORDBOT_TOKEN', 'token')
|
||||
scheduler_hostname = os.environ.get('SCHEDULER_API_HOSTNAME', 'tv.example.com')
|
||||
|
||||
# Scheduler
|
||||
scheduler = AsyncIOScheduler()
|
||||
|
||||
# Intents
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
# Client
|
||||
client = discord.Client(intents=intents)
|
||||
|
||||
# Define an event when the bot is ready
|
||||
|
@ -43,4 +50,19 @@ async def on_message(message):
|
|||
if message.content.startswith('!epg'):
|
||||
await epg(message)
|
||||
|
||||
client.run(bot_token)
|
||||
client.run(bot_token)
|
||||
|
||||
def tick():
|
||||
print('Tick! The time is: %s' % datetime.now())
|
||||
|
||||
scheduler.add_job(tick, 'interval', seconds=3)
|
||||
scheduler.start()
|
||||
|
||||
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
|
||||
|
||||
# Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
|
||||
try:
|
||||
asyncio.get_event_loop().run_forever()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in a new issue