Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chatterbot on nextcord(discord.py) not create db.sqlite3 #2238

Open
Ghieh44 opened this issue Mar 4, 2022 · 2 comments
Open

Chatterbot on nextcord(discord.py) not create db.sqlite3 #2238

Ghieh44 opened this issue Mar 4, 2022 · 2 comments

Comments

@Ghieh44
Copy link

Ghieh44 commented Mar 4, 2022

Hello, I'm creating a chatterbot with this library in nextcord to use in discord and it works, but it doesn't create the "db.sqlite3" file that makes possible to learn new words and I'm trying to solve this bug, in case anyone have an idea of solving this problem, I would like to comment here.

if i resolve, i'll tell how i did it

The code:

#imports
import nextcord
from nextcord.ext import commands
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer

#variable
bot = commands.Bot(command_prefix='$', activity=nextcord.Game(name='!co pra falar comigo!'))
chatbot = ChatBot('Cobaia')

#conversation list
conversation = [
    'Ola',
    'Ola, tudo bem?',
    'Tudo e você?',
    'Estou bem',
    'Faz o que de bom?',
    'Conversando',
    'Você gosta de comida?',
    'Sim, eu amo comer e você?',
    'Eu também'
]

#chatterbot train
trainer = ListTrainer(chatbot)
trainer.train(conversation)

#bot online warning
@bot.event
async def on_ready():
    print(f'Ola mestre! me loguei como {bot.user}')

#chatterbot command
@bot.event
async def on_message(message):
    if message.author == bot.user:
        return

    if message.content.startswith('!co'):
        response = chatbot.get_response('')
        await message.channel.send(response)

#run
bot.run('token')

I'm not good in english, but i understand if you write in english

@Ghieh44
Copy link
Author

Ghieh44 commented Mar 4, 2022

(2 hours later)

I already found the answer:

really the chatterbot doesn't work right inside the bot, but nothing prevents it from working outside the bot.

So I deleted all the chatterbot inside the file (called ptreino.py) and created a new one with the chatterbot library and in the end, instead of just doing it with while True, I created a def that has the variable "Speak", thus doing with that it responds what is in the variable "Speak" with return(response)

In the file that has the bot. I put "import ptreino" and in the part that was going to contain the content, I made it create the variable "speech" containing the content and then sending it to the def created in ptreino.py

code for the two below:

ptreino.py

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer

chatbot = ChatBot('Cobaia')

conversation = [
    'Ola',
    'Ola, tudo bem?',
    'Tudo e você?',
    'Estou bem',
    'Faz o que de bom?',
    'Conversando',
    'Você gosta de comida?',
    'Sim, eu amo comer e você?',
    'Eu também'
]

trainer = ListTrainer(chatbot)
trainer.train(conversation)

def botfala(fala):
    while True:
        try:
            resposta = chatbot.get_response(fala)
            return(resposta)

        except(KeyboardInterrupt, EOFError, SystemExit):
            break

discord_bot.py:

#imports
import nextcord
from nextcord.ext import commands
from ptreino import botfala

#variable
bot = commands.Bot(command_prefix='$', activity=nextcord.Game(name='!co pra falar comigo!'))

#bot online warning
@bot.event
async def on_ready():
    print(f'Ola mestre! me loguei como {bot.user}')


#chatterbot command
@bot.event
async def on_message(message):
    if message.author == bot.user:
        return

    if message.content.startswith('!co'):
        fala = message.content[:2]
        await message.channel.send(botfala(fala))

#run
bot.run('token')

Hope this helps who was having the same problem as me

@Ghieh44
Copy link
Author

Ghieh44 commented Mar 4, 2022

i'll keep this post open for anyone want some help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant