Discord.py recognizing on_message client event, but IF statements not responding

I am working on a Discord bot and in this case want the bot to roll a 6 sided die when any user gives the "roll" command. See code below. Oddly enough this was working just fine, but now the print(worked) triggers and the if p_message statements do nothing. I get no errors, it just doesn’t work.

import discord
import random

intents = discord.Intents.all()
intents.message_content = True
client = discord.Client(intents=intents)

@client.event
async def on_message(message):
  p_message = message
  print("worked")

  if p_message == "roll":
    return str(random.randint(1, 6))

client.run('***') #my token

I have tried ensuring that message is a str but it makes no difference. Again, this code worked previously (at 1am when I was probably too tired to be writing code) and throws no error. It just doesn’t respond to the command at all in discord.

>Solution :

import discord
import random

# change .all to .default
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)


@client.event
async def on_message(message):
    # use message.content
    if message.content == "roll":
        # send message to the channel that someone types "roll"
        await message.channel.send(random.randint(1, 6))


client.run('***')  # my token

Leave a Reply