1
0

main.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ### IMPORTS ###
  2. # Discord #
  3. import discord
  4. from discord.ext import commands
  5. from discord import app_commands
  6. # For env variables #
  7. from os import environ
  8. from dotenv import load_dotenv
  9. # Other #
  10. from typing import Literal
  11. # Commands #
  12. from day_planning import today, tomorrow
  13. ### BOT CLASS ###
  14. class Bot(commands.Bot):
  15. def __init__(self):
  16. intents = discord.Intents.default()
  17. intents.message_content = True
  18. super().__init__(command_prefix = "?", intents = intents)
  19. async def setup_hook(self):
  20. await self.tree.sync(guild= discord.Object(id=guild))
  21. print("Bot started")
  22. async def on_command_error(self, ctx, error):
  23. await ctx.reply(error, ephemeral = True)
  24. ### VARIABLES ###
  25. load_dotenv()
  26. token = environ["TOKEN"]
  27. guild = environ["GUILD"]
  28. bot = Bot()
  29. ### COMMANDS ###
  30. @bot.hybrid_command(name="day", with_app_command=True, description="Give your attends for one day")
  31. @app_commands.guilds(discord.Object(id=guild))
  32. @app_commands.describe(date="The day for which your attends will be displayed")
  33. async def day(ctx, date: Literal["today", "tomorrow"]):
  34. if date == "today":
  35. msg = today()
  36. elif date == "tomorrow":
  37. msg = tomorrow()
  38. else:
  39. msg = "This date doesn't exist"
  40. await ctx.reply(msg)
  41. bot.run(token)