Reputation: 73
import os
import discord
from discord import Intents
from dotenv import load_dotenv
from chatbot import ChatBot
load_dotenv()
discord_token = os.getenv('DISCORD_TOKEN')
chatbot = ChatBot()
intents = Intents.default()
intents.typing = False
intents.presences = False
intents.messages = True # Enable the messages intent
client = discord.Client(intents=intents)
chat_history = []
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
print("Received a message") # Add this line
if message.author == client.user: # Ignore messages from the bot itself
return
print('Received message:', message)
print(f"Received message content: {message.clean_content}")
if message.content.startswith('/ask'):
user_input = message.content[5:].strip()
print('User input: ', repr(user_input))
print('Received user input: {}'.format(user_input)) # Print the user's question to the console
response = chatbot.get_response(user_input, chat_history)
await message.channel.send(response)
client.run(discord_token)
Console:
We have logged in as ask-Bot#1060 Received a message Received message: <Message id=1117888736563306637 channel= type=<MessageType.default: 0> author=<Member id=940462143654998096 name='Dane W' discriminator='4497' bot=False nick=None guild=> flags=> Received message content:
I typed "/ask tell me about the striking offense of brandon moreno" into Discord. I expected my console to return that value as message.content.
The Discord bot has been given all necessary permissions and exists in the channel I am typing to message into.
Upvotes: 2
Views: 292
Reputation: 3602
You are missing intents.message_content = True
in your code.
intents.messages
is not enough anymore.
Find out more about it here: message_content
Upvotes: 2