bereal-discord/bot/app.py

38 lines
1.0 KiB
Python
Raw Normal View History

import time
2024-03-02 20:41:56 +00:00
import discord, asyncio
import os
from discord.ext import commands
from discord import app_commands
import database.controller
intents = discord.Intents.default()
intents.members = True
intents.dm_messages = True
app = commands.Bot(command_prefix=",", intents=intents)
app.db = database.controller.Database("database.db")
# load cogs
async def load_cogs():
for filename in os.listdir("bot/commands"):
if filename.endswith(".py"):
await app.load_extension(f"bot.commands.{filename[:-3]}")
async def time_to_bereal():
# Get subscribers
2024-03-02 22:31:47 +00:00
time = int(time.time())
subscribers = app.db.get_subscribers()
# Send message to all subscribers
for subscriber in subscribers:
user = await app.fetch_user(subscriber.user_id)
2024-03-02 22:31:47 +00:00
await user.send(f"# :warning: It's time to BeReal.\nOpen BeReal. to post what you are doing right now.\n<t:{time}:R>")
app.time_to_bereal = time_to_bereal
2024-03-02 20:41:56 +00:00
@app.event
async def on_ready():
print("Running")
await load_cogs()
await app.tree.sync()