add the apscheduler

This commit is contained in:
deflax 2024-01-16 17:42:22 +02:00
parent bc2796492a
commit fcdef2e17c

View file

@ -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