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!