Search code examples
pythondiscord

Discord bot python, message.contents always detected as empty


I've been making a discord bot for a friend, and he asked me to implement a part where if a user says a certain phrase, then the bot will respond with something back.

I've tried editing the code and make it less bulky, and I've turned on Message content intent, but nothing is working, and I have also looked at around ten forums about this, and no solutions worked, here is the code which prints out and reads the message content.

    async def on_message(message):
        if message.author == client.user:
            return

            # Get data about the user
        username = str(message.author)
        user_message = str(message.content)
        channel = str(message.channel)

        # Debug printing
        print(f"{username} said: '{user_message}' ({channel})")

Solution

  • It sounds like your issue may be related to intents:

    import discord
    
    # if this doesn't work, try "all" instead of "default"
    intents = discord.Intents.default()
    
    client = discord.Client(intents=intents)
    

    If this isn't the problem, post a minimal reproducible example and it will be easier to pinpoint the exact issue.