diff --git a/src/discordbot/discordbot.py b/src/discordbot/discordbot.py index 1051053..e4f8d0c 100644 --- a/src/discordbot/discordbot.py +++ b/src/discordbot/discordbot.py @@ -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) \ No newline at end of file +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 +