pythondiscord.pychatterbot

Trying to run chatbot on Discord but get AttributeError: type object 'ChatBot' has no attribute 'request'


The discord bot comes online but when I try talking to the chat bot using "$prototypebot" on Discord it throws up this error message on my console:

    Ignoring exception in on_message
    Traceback (most recent call last):
      File "C:\Users\amjad\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 343, in _run_event        
        await coro(*args, **kwargs)
      File "C:\Users\amjad\OneDrive\Documents\Goldsmiths\Year 3\Final Year\Project\Chatterbot\main.py", line 66, in on_message
        response = ChatBot.request(message.content[13:])
    AttributeError: type object 'ChatBot' has no attribute 'request'

My code is as below:

 # Import modules
    from chatterbot import ChatBot
    from chatterbot.trainers import ListTrainer
    from chatterbot.trainers import ChatterBotCorpusTrainer

    import discord

    # Initialise data
    bot = ChatBot(name = 'DiscBot', read_only = True,
                    logic_adapters = [
                        'chatterbot.logic.MathematicalEvaluation',
                        'chatterbot.logic.BestMatch',
                        ])

    small_talk = [
        'hi there!',
        'hi!',
        'how do you do?',
        'how are you?',
        'i\'m cool.',
        'fine, you?',
        'always cool.',
        'i\'m ok',
        'glad to hear that.',
        'i\'m fine',
        'glad to hear that.',
        'i feel awesome',
        'excellent, glad to hear that.',
        'not so good',
        'sorry to hear that.',
        'what\'s your name?',
    ]

    list_trainer = ListTrainer(bot)

    # Train data
    for item in (small_talk):
        list_trainer.train(item)

    # Create a new trainer for the chatbot
    trainer = ChatterBotCorpusTrainer(bot, show_training_progress = False)

    # Train based on the english corpus
    trainer.train("chatterbot.corpus.english")
    # Train based on a custom written corpus
    trainer.train("chatterbot.corpus.custom.games")

    client = discord.Client()

    @client.event
    async def on_message(message):
        if message.author == client.user:
            return

        if message.content.startswith("$prototypebot"):
            response = bot.request(message.content[13:])
            await message.channel.send(response)

    client.run("TOKEN")

How do I solve the error. Have already tried researching but to no avail. Uninstalled and reinstalled chatterbot, changed bot names ect


Solution

  • Instead of bot.request, I think you meant to use bot.get_response.