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:
JavaScript
x
20
20
1
import os
2
from discord.ext import commands
3
from datetime import datetime
4
5
client = commands.Bot(command_prefix = ";", help_command = None)
6
7
dates = datetime.now()
8
date = datetime.today()
9
client.event
10
async def on_ready():
11
print("bot is ready")
12
13
14
client.event
15
async def on_message(message):
16
author = message.author
17
text = message.content
18
print(author + " said at " + dates + " : " + text)
19
client.process_commands(message)
20
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.
JavaScript
1
3
1
intents = discord.Intents.default()
2
client = commands.Bot(command_prefix = ";", help_command = None, intents = intents)
3
Your corrected code should be something like this:
JavaScript
1
21
21
1
import os
2
from discord.ext import commands
3
from datetime import datetime
4
5
intents = discord.Intents.default()
6
client = commands.Bot(command_prefix = ";", help_command = None, intents = intents)
7
8
dates = datetime.now()
9
date = datetime.today()
10
@client.event
11
async def on_ready():
12
print("bot is ready")
13
14
15
@client.event
16
async def on_message(message):
17
author = message.author
18
text = message.content
19
print(author + " said at " + dates + " : " + text)
20
await client.process_commands(message)
21