我想用Google Bard做一个聊天机器人。我尝试使用Chatgpt,但我遇到了一些错误并放弃了。
现在我只需要基本代码只是我发了一条信息,机器人就回应了。
现在,因为有接近0教程,我用谷歌吟游诗人本身,所以我很清楚有些事情是错误的。我只是不知道是什么
下面是我当前的代码:
const {Dialogflow} = require('@google-cloud/dialogflow');
const dialogflow = new Dialogflow({
projectId: 'my project id',
credentials: {
key: 'my api key',
},
});
// Create a variable to store the conversation state.
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent ] });
client.on('ready', () => {
console.log('Bot is ready!')
})
const ignore = '!' && '?'
const botchanelid = '1155186010485960909'
client.on('messageCreate', async (msg) => {
if (msg.content.startsWith(ignore) || msg.channelId != botchanelid || msg.author.bot) return;
dialogflow.query(`${msg}`, conversationState, (err, response) => {
if (err) {
console.log(err);
return;
}
// Get the response from Dialogflow.
const responseText = response.result.text;
// Update the conversation state.
conversationState = response.result.conversationState;
// Display the response to the user.
msg.reply(responseText)
})
})
现在我的错误是TypeError: Dialogflow is not a constructor
。我想要一个答案,告诉我我做错了什么,并完全调整它,所以我明白。
我的版本是6.1.0
如果你需要任何额外的信息,请在评论中注明!
1条答案
按热度按时间cclgggtu1#
下面是一个增强的代码: