Discord Chatterbot Python
import discord
from dotenv import load_dotenv
from chatterbot import ChatBot
chatbot = ChatBot("ur bot's name")
from chatterbot.trainers import ListTrainer
load_dotenv()
TOKEN = 'Your discord bot token'
trainer = ListTrainer(chatbot)
file = open('message.txt', 'r') # messages are being saved in a .txt file
conversation = [line for line in file]
conversation = list(dict.fromkeys(conversation)) # remove duplicate for training conversation
trainer.train(conversation)
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user.name} has connected to Discord!')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == None:
await message.channel.send('Nothing is being sent, please try type something')
response = chatbot.get_response(message.content) # use chatterbot to process and get response
print(f'{message.channel}, {message.author.name}: {message.content} response: {response}')
await message.channel.send(response)
client.run(TOKEN)
Motionless Macaque