Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My python discord bot isn't getting any user messages

Im trying to make a discord bot in python, I want it to respond based on what the users message is, yet for some reason it isn’t getting there message. It can see what their name is and what channel they are in but the user message isn’t being read

async def send_message(message, user_message):
    try:
        response = responses.handle_response(user_message)
        await message.channel.send(response)
    except Exception as e:
        print(e)


def run_discord_bot():
    TOKEN = 'my discord bot token is here'
    client = discord.Client(intents=discord.Intents.default())

    @client.event
    async def on_ready():
        print(f'{client.user} is now running!')

    @client.event
    async def on_message(message):
        if message.author == client.user:
            return
        
        username = str(message.author)
# nothing is gettiing saved in the user message ??
        user_message = str(message.content)
        channel = str(message.channel)

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

        # code for bot to respond to messages
        response = responses.handle_response(user_message)
        print(f"Generated response: {response}")
        await send_message(message, user_message)

    client.run(TOKEN)

I changed the permissions to make it so the bot can read messages in channels yet that didn’t fix it. I quadruple checked my code to see if something was typed wrong but nothing I can find to be the problem. It gets username and channel perfectly fine. My test print statement prints Username said: ” (channel). The message is always empty for some reason?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Discord has changed how their event delivery system works a while ago, you need to explicitly opt into message content. Go to your bot’s settings, and enable the message intent. Restart the bot, and it should work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading