Nikos Sakellariou
Nikos Sakellariou

Reputation: 21

discord bot does not print message.content

I am using the following code to print the latest message on a specific discord channel, but it always brings an empty string.

from termcolor import colored
import discord

intents = discord.Intents.default()
intents.members = True
intents.messages = True

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

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

@client.event
async def on_message(message):
    # Check if the message was sent in the specific channel you want to read from
    if message.channel.id == CHANNELID:  # replace CHANNEL_ID with the ID of the channel you want to read from
        print(colored(message.content, 'green'))

client.run('TOKEN')

Any ideas?

Message Content Intent is correctly enabled on the application, and the bot has read message and read message history permissions on the channel.

Privileged Gateway Intents is set up as instructed

Upvotes: 2

Views: 422

Answers (1)

raphiel
raphiel

Reputation: 852

this is the case if your bot dont have the intents setup.

Go to the Discord Developer Portal and to your Bot, then go to Bot and go to the Privilege Gateway Intents and check the Message Content Intent

you have already specified the intents in your code so this should do it

Upvotes: 0

Related Questions