Trying to run chatbot on Discord but get AttributeError: type object 'ChatBot' has no attribute 'request'
Trying to run chatbot on Discord but get AttributeError: type object 'ChatBot' has no attribute 'request'
Discord 机器人上线了,但是当我尝试在 Discord 上使用“$prototypebot”与聊天机器人交谈时,它在我的控制台上抛出了这个错误消息:
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'
我的代码如下:
# 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")
我该如何解决这个错误。已经尝试研究但无济于事。卸载并重新安装了 chatterbot,更改了 bot 名称等
而不是 bot.request
,我认为你打算使用 bot.get_response
。
Discord 机器人上线了,但是当我尝试在 Discord 上使用“$prototypebot”与聊天机器人交谈时,它在我的控制台上抛出了这个错误消息:
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'
我的代码如下:
# 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")
我该如何解决这个错误。已经尝试研究但无济于事。卸载并重新安装了 chatterbot,更改了 bot 名称等
而不是 bot.request
,我认为你打算使用 bot.get_response
。