Search code examples
pythondiscorddiscord.pyspyder

message.content is allways empty. no matter the content


I am trying to access the content of a message and print it using discord.py. The problem is, that the content is allways empty no matter what. The code works on my laptop but just refuses to work on this pc. The same has already happened when trying to run other, more complex, codes that worked on other devices. There are no errors showing up.

import nest_asyncio
nest_asyncio.apply()
import discord

TOKEN = "TOKEN"

client = discord.Client(intents=discord.Intents.default())

@client.event
async def on_ready():
    print("logged in as {0.user}".format(client))
    

@client.event
async def on_message(message):
    
    username = str(message.author).split("#")[0]
    user_message = message.content
    channel = str(message.channel.name)
    print(f"{username}: {user_message} ({channel})")
    
client.run(TOKEN)

Solution

  • You need to enable the Guild Message Intent: https://discordpy.readthedocs.io/en/latest/api.html#discord.Intents.guild_messages