Code: Select all
import discord
from discord.ext import commands, tasks
from flask import Flask
import asyncio
from threading import Thread
# Flask web server setup
app = Flask(__name__)
@app.route('/')
def home():
return "Bot is running!"
# Discord bot setup
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
# User calendar data storage (for persistent storage, consider using a database or file)
user_calendars = {}
user_channel_ids = {}
# Step 1: Setup the calendar
@bot.command(name='setup_calendar', help='Set up the calendar with your custom specifications.')
async def setup_calendar(ctx):
user_id = ctx.author.id
user_calendars[user_id] = {"step": 1}
await ctx.send("Let's set up your custom calendar! I'll guide you through the process step by step.")
# Initialization logic
user_data = user_calendars[user_id]
user_data["remaining_days"] = 1 # Initialize remaining days to 1 (or a valid start day)
user_data["current_month_index"] = 0 # Initialize to the first month
user_data["step"] = 1 # Continue the setup steps from the beginning
# Step 1: Ask for the year
await ctx.send("Step 1: What year would you like to use for your custom calendar?")
# Event handler to process messages
@bot.event
async def on_message(message):
if message.author == bot.user:
return # Ignore bot's own messages
user_id = message.author.id
if user_id in user_calendars:
user_data = user_calendars[user_id]
step = user_data["step"]
if step == 1:
try:
year = int(message.content)
if year