-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
50 lines (39 loc) · 1.31 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This example requires the 'message_content' intent.
import os
import datetime
from zoneinfo import ZoneInfo
import discord
from discord.ext import tasks
import essen
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
CHANNEL = int(os.getenv('CHANNEL'))
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
#Create the time on which the task should always run
foodtime = datetime.time(hour=11, minute=25, tzinfo=ZoneInfo("Europe/Berlin"))
@tasks.loop(time = foodtime) #Create the task
async def menu():
print('Send menu')
channel = client.get_channel(CHANNEL)
menu = essen.get_today_menu("mensa-garching")
if menu:
menu_message = essen.print_menu(menu)
await channel.send("Time for lunch!")
await channel.send(menu_message)
@client.event
async def on_ready():
if not menu.is_running():
menu.start() #If the task is not already running, start it.
print("Menu task started")
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('lunch menu'):
menu = essen.get_today_menu("mensa-garching")
menu_message = essen.print_menu(menu)
await message.channel.send(menu_message)
client.run(TOKEN)