Skip to content
Advertisement

My bot wont run the on_message/on_ready event properly

When i tried to start up my bot, it wouldnt run the on_message event and it wouldnt run the on_ready event either.

Here is my code:

import os
from discord.ext import commands
from datetime import datetime

client = commands.Bot(command_prefix = ";", help_command = None)

dates = datetime.now()
date = datetime.today()
client.event
async def on_ready():
    print("bot is ready")


client.event
async def on_message(message):
    author = message.author
    text = message.content
    print(author + " said at " + dates + " : " + text)
    client.process_commands(message)

I have tried to get rid of the on_message event to see if that was the problem, and it didnt fix it. Does anyone have a fix for this?

Advertisement

Answer

You are not actually using the correct decorators for the on_ready and on_message. Any decorator should start with a @, notice how you are only using client.event instead of @client.event.

Also make sure to activate some intents for your bot or you will not be able to access some specific information.

intents = discord.Intents.default()
client = commands.Bot(command_prefix = ";", help_command = None, intents = intents)

Your corrected code should be something like this:

import os
from discord.ext import commands
from datetime import datetime

intents = discord.Intents.default()
client = commands.Bot(command_prefix = ";", help_command = None, intents = intents)

dates = datetime.now()
date = datetime.today()
@client.event
async def on_ready():
    print("bot is ready")


@client.event
async def on_message(message):
    author = message.author
    text = message.content
    print(author + " said at " + dates + " : " + text)
    await client.process_commands(message)
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement