Discord bot can't send messages from the server but sends messages from dm

42 Views Asked by At

I have made one discord bot in the past it work perfectly but when I tried makeing another just like that it don't work it doesn't respond to my messages in the server but it respond in the private dms I tried to debug it by print statements but it don't receive the message from the server, I have checked the permissions and remove and add the bot again and also made another one and new servers but both of them don't message in servers

It's the code I written.



import discord

import os



intents = discord.Intents.default()

intents.messages = True  # Enable message events



key = os.environ['Key']



client = discord.Client(intents=intents)



@client.event

async def on_ready():

    print('Connected!')



@client.event

async def on_message(message):

    if message.author == client.user:

        return



    print(f"Received message: {message.content}")  # Debug print statement



    if message.content.startswith('hello'):

        print('Responding to hello message')  # Debug print statement

        await message.channel.send('Hello!')



client.run(key)

Thank-you

The bot works fine when I chat in the dms but it can't read the messages on a server

1

There are 1 best solutions below

3
RΛNEL SΛRΛNIΛ . Music On

Thanks after enabling this it worked

Idk why it work but, By enabling server members intend and message content intend it start to read from the channels of the server maybe it would work after just enabling message content intend as it is required to get message contents from "most message" (I has it already enable but didn't worked) but after enabling server members intend it stared to get the messages and able to respond. Thanks.