Im trying to make a discord bot in python, I want it to respond based on what the users message is, yet for some reason it isn’t getting there message. It can see what their name is and what channel they are in but the user message isn’t being read
async def send_message(message, user_message):
try:
response = responses.handle_response(user_message)
await message.channel.send(response)
except Exception as e:
print(e)
def run_discord_bot():
TOKEN = 'my discord bot token is here'
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print(f'{client.user} is now running!')
@client.event
async def on_message(message):
if message.author == client.user:
return
username = str(message.author)
# nothing is gettiing saved in the user message ??
user_message = str(message.content)
channel = str(message.channel)
print(f"{username} said: '{user_message}' ({channel})")
# code for bot to respond to messages
response = responses.handle_response(user_message)
print(f"Generated response: {response}")
await send_message(message, user_message)
client.run(TOKEN)
I changed the permissions to make it so the bot can read messages in channels yet that didn’t fix it. I quadruple checked my code to see if something was typed wrong but nothing I can find to be the problem. It gets username and channel perfectly fine. My test print statement prints Username said: ” (channel). The message is always empty for some reason?
>Solution :
Discord has changed how their event delivery system works a while ago, you need to explicitly opt into message content. Go to your bot’s settings, and enable the message intent. Restart the bot, and it should work.