Discord bot can not read content of the message
Question:
HI I want to make a bot on discord. I can make a bot with see that message is coming. But it can not see a content of the message.
my code:
import discord
import os
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print("This is user {0.user}".format(client))
@client.event
async def on_message(message):
print(message)
print(message.content)
if message.author == client.user:
return
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
my_secret = os.environ['TOKEN3']
client.run(my_secret)
my output:
<Message id=1089613042033111062 channel= type=<MessageType.default: 0> author=<Member id=1029808272267550740 name=’l_programmer’ discriminator=’1926′ bot=False nick=None guild=> flags=>
Answers:
You need to enable the message content intent in your bot itself.
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
HI I want to make a bot on discord. I can make a bot with see that message is coming. But it can not see a content of the message.
my code:
import discord
import os
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print("This is user {0.user}".format(client))
@client.event
async def on_message(message):
print(message)
print(message.content)
if message.author == client.user:
return
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
my_secret = os.environ['TOKEN3']
client.run(my_secret)
my output:
<Message id=1089613042033111062 channel= type=<MessageType.default: 0> author=<Member id=1029808272267550740 name=’l_programmer’ discriminator=’1926′ bot=False nick=None guild=> flags=>
You need to enable the message content intent in your bot itself.
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)