import discord
# Create a client instance
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
intents.messages = True # Enable intents for messages
client = discord.Client(intents=intents)
# Handle the on_ready event
@client.event
async def on_ready():
print(f'Logged in as {client.user.name}')
# Set the online status
await client.change_presence(
status=discord.Status.do_not_disturb, activity=discord.Game(name="TESTS")
)
# Handle the on_message event
@client.event
async def on_message(message):
print(f'Received message: {message.content}')
if message.author == client.user:
return
if message.content.startswith('!hello'):
await message.channel.send('Hello!')
# Run the bot
client.run("My token")
if i send message on a server bot not responde (i gave him all of premissions) i asked chat gpt and it don't help :'(
There's a difference between the intents.message and the intents.message_content.
While the first is a general intent to have access to the message context, it does Not have access to message content within a Guild, as it became a private intent about a year ago (You can check the Dev notes here); It does however have access to the content within a DM.
Therefore, in order for you to have access to the content of both Guild and DM message contents, you need to declare the intents to message_content
as below:
intents.message_content = True