Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

PREVIOUS NEXT
Code Example
Python :: django migrate 
Python :: getting-the-last-element-of-a-list 
Python :: dataframe divided by rowsum 
Python :: stripping whitespace in python 
Python :: python comment header 
Python :: how to interrupt a loop in python 
Python :: Flatten List in Python With Itertools 
Python :: how to uninstall python 
Python :: Binary search tree deleting in python 
Python :: to_datetime with non zero padded values python 
Python :: sns.savefig 
Python :: how to use with statementin python 2.4 
Python :: how to call a class from another class python? 
Python :: How to build a Least Recently Used (LRU) cache, in Python? 
Python :: pyqt5 app styles 
Python :: how to get left click input in pygame 
Python :: url routing in django 
Python :: separate each characters by commas into a single characters separated by commas 
Python :: sum of fraction numbers in python 
Python :: python bug 
Python :: django http response 204 
Python :: where are docker logs 
Python :: df max count syntax 
Python :: midpoint circle drawing algorithm 
Python :: plot multiple columns in different colors plotly 
Python :: django filter values with OR operator 
Python :: ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters 
Python :: binary tree python implementation 
Python :: access cmd with python 
Python :: *kwargs 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =