Why is my Discord bot not responding to commands?

Hello everyone! I’m encountering an issue with my Discord bot that I built using the discord.py library. It was functioning well until recently, but now, when I input commands, the bot doesn’t respond at all. There aren’t any error messages in the logs, which is puzzling.

Here’s the code for my bot:

bot.py

import discord
from discord.ext import commands
from datetime import datetime, timedelta
from icalendar import Calendar
from server import start_server
from settings import BOT_TOKEN, GUILD_ID

start_server()

permissions = discord.Intents.default()
permissions.message_content = True

bot = commands.Bot(command_prefix='!', intents=permissions)

@bot.event
async def on_ready():
    print(f'Bot is ready as {bot.user}')

@bot.event
async def on_message(msg):
    if msg.author == bot.user:
        return
    await bot.process_commands(msg)

@bot.command()
async def time(ctx):
    current_time = datetime.now()
    formatted_time = current_time.strftime("%d/%m/%Y")
    await ctx.send('Today is ' + str(formatted_time))

@bot.command()
async def schedule(ctx, *arguments):
    if not arguments:
        await ctx.send("Please specify 'now' or 'tomorrow' after the !schedule command.")
        return
    
    if arguments[0].lower() == 'now':
        await show_schedule(ctx, datetime.now().date())
    elif arguments[0].lower() == 'tomorrow':
        await show_schedule(ctx, datetime.now().date() + timedelta(days=1))
    else:
        await ctx.send("Invalid argument. Use 'now' or 'tomorrow' after !schedule.")

async def show_schedule(ctx, selected_date):
    classes = []
    times = []
    rooms = []
    
    file_handle = open('calendar/schedule.ics', 'rb')
    calendar_data = Calendar.from_ical(file_handle.read())
    
    today = datetime.now().date()
    date_string = today.strftime("%Y%m%d")
    display_date = today.strftime("%d/%m/%Y")
    
    for component in calendar_data.walk('VEVENT'):
        event_start = component.get("DTSTART")
        start_time = event_start.dt
        event_date = start_time.strftime("%Y%m%d")
        time_format = start_time.strftime("%Hh%M")
        room = component.get("LOCATION")
        
        if event_date == date_string:
            classes.append(component.get("SUMMARY"))
            times.append(time_format)
            rooms.append(room)
    
    file_handle.close()
    
    embed_message = discord.Embed(
        title=f"Schedule for {display_date}",
        description="Your classes today:",
        color=0x2E8B57
    )
    
    if len(classes) > 0:
        embed_message.add_field(
            name=classes[0],
            value=f"{times[0]} in **{rooms[0].lower()}**",
            inline=False
        )
        if len(classes) > 1:
            embed_message.add_field(
                name=classes[1],
                value=f"{times[1]} in **{rooms[1].lower()}**",
                inline=False
            )
    else:
        embed_message.add_field(
            name="No classes",
            value="No scheduled classes today.",
            inline=False
        )
    
    await ctx.send(embed=embed_message)

@bot.command()
async def status(ctx):
    pass

@bot.event
async def on_message(msg):
    if msg.content.startswith('hello'):
        response_embed = discord.Embed(
            title="Hello!",
            description="Nice to meet you!",
            color=0xFF6347
        )
        await msg.channel.send(embed=response_embed)

bot.run(BOT_TOKEN)

I’m using Replit along with an uptime monitoring service. Any suggestions on what might be causing this issue? Thank you for your assistance!

Had the same problem with my Replit bot. Yeah, check for duplicate event handlers like others said, but also make sure your uptime monitor is actually working. These services sometimes ping the wrong endpoint or just stop working without telling you. I see you’re opening that calendar file without any error handling - if it gets corrupted or becomes inaccessible, your bot will fail silently. Wrap those file operations and calendar parsing in try-catch blocks. Empty status command probably means your deployment didn’t finish properly. Check your Replit logs for startup errors that aren’t showing in console.

you’ve got duplicate on_message events - that’ll break things. the second one’s missing bot.process_commands(msg) so ur commands won’t work. just delete the duplicate at the bottom and keep the first one.

I spotted another issue beyond the duplicate event handlers Claire mentioned. Your show_schedule function has a hardcoded date problem. You’re passing selected_date as a parameter but then immediately overriding it with today = datetime.now().date() inside the function. This means your schedule command always shows today’s events - doesn’t matter if you specify ‘now’ or ‘tomorrow’. Fix this by actually using the selected_date parameter you’re passing in, and double-check that your calendar file path is correct and accessible in your Replit environment.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.