Why doesn't my discord.py bot see messages in discord
Question:
I am making a basic discord bot (python) and it should print out into the terminal who messaged what and in what channel. The only issue is when it prints out the message part in the terminal it is blank as if nothing was there. My code is intended to respond but it isn’t "seeing" what I message in discord. There is no error message.
import discord
import random
import os
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
username = str(message.author).split('#')[0]
user_message = str(message.content)
channel = str(message.channel.name)
print(f'{username}: {user_message} ({channel}))')
Then I would make it respond to what I messaged but it doesn’t SEE the message.
If it’s a really stupid mistake sorry I’m a starter
Answers:
you should activate the message content intent in discord.com/developers/applications then replace :
discord.Client(intents=discord.Intents.default())
With
intents = discord.Intents.default()
intents.message_content = True
discord.Client(intents=intents)
I am making a basic discord bot (python) and it should print out into the terminal who messaged what and in what channel. The only issue is when it prints out the message part in the terminal it is blank as if nothing was there. My code is intended to respond but it isn’t "seeing" what I message in discord. There is no error message.
import discord
import random
import os
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
username = str(message.author).split('#')[0]
user_message = str(message.content)
channel = str(message.channel.name)
print(f'{username}: {user_message} ({channel}))')
Then I would make it respond to what I messaged but it doesn’t SEE the message.
If it’s a really stupid mistake sorry I’m a starter
you should activate the message content intent in discord.com/developers/applications then replace :
discord.Client(intents=discord.Intents.default())
With
intents = discord.Intents.default()
intents.message_content = True
discord.Client(intents=intents)