I have created a Discord bot that functions as intended initially, but it becomes unresponsive after running for a while. While the bot appears online, I cannot execute any commands, including the shutdown command.
I’m uncertain whether the issue lies within the code or if it’s related to the environment. I typically run the bot in Visual Studio Code, but encountered errors when running it via the command prompt due to a missing main function.
from discord.ext import commands
import discord
import asyncio
BOT_TOKEN = "your_bot_token_here"
CHANNEL_ID = 123456789
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
@bot.event
async def on_message(message: discord.Message):
if "https://twitter.com/" in message.content:
new_message = message.content[:8] + "vx" + message.content[8:]
await message.channel.send(new_message)
await message.delete()
await bot.process_commands(message)
@bot.event
async def on_message(message: discord.Message):
if "https://x.com/" in message.content:
new_message = message.content[:8] + "fixv" + message.content[8:]
await message.channel.send(new_message)
await message.delete()
await bot.process_commands(message)
@bot.event
async def on_message(message: discord.Message):
if "https://www.tiktok.com/t/ZT8QnN8hg/" in message.content:
new_message = message.content[:8] + "vx" + message.content[8:]
await message.channel.send(new_message)
await message.delete()
await bot.process_commands(message)
@bot.command()
@commands.is_owner()
async def shutdown(context):
exit()
bot.run(BOT_TOKEN)
As I’m still learning Python, I’m curious about potential reasons for this freezing issue. Could it result from my computer entering sleep mode? Or could there possibly be a memory leak? Any guidance would be greatly appreciated because I have not found satisfactory information online regarding this problem.