message.content is empty for bot client (pycord)

Question:

I have simplest python program of discord bot

from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_message(msg):
    print(msg.content)

bot.run('token')

And it prints just empty string. Before that I tried bot.command() but bot simply doesn’t responds to it probably because message is empty so like there’s no command. I saw this problem mostly occurs for selfbot clients but in my case client is bot. Would be glad for any help

Asked By: The Dark

||

Answers:

You have to enable the message intents on https://discord.com/developers/applications
and need to pass them to your commands.Bot

bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())

would be an example of how you can do that.

Answered By: Fién
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.