Hi, this is my first time coding. I have an ecosystem I want to build but coding this discord bot is my proof of concept. I have deployed my code to google firebase and getting my bot come online in discord works fine. In my code I also have it set to where my bot only listens after you use a specific phrase to “wake it up”. You can also “put it to sleep”. However it keeps throwing errors when it comes to interfacing with the api. My api key is correct for both discord and openai. I’ve narrowed it down to the code that is actually supposed to generate the prompt, but I can’t figure out what I’m doing wrong. Any help would be greatly appreciated.
Not listing all the dependencies or setup variables because all of those work so far.
Code for completions:
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", async function (message) {
if (message.content.toLowerCase() == 'hi jarvis') {
listening = true;
message.reply("Hello. Jarvis is operational. All systems go.");
return;
}
if (message.content.toLowerCase() == 'bye jarvis') {
listening = false;
message.reply("Goodbye sir.");
return;
}
});
client.on("messageCreate", async function (message) {
if (message.author.bot) return;
if(listening){
try {
const prompt = message.content;
const completionRequest = {
model: "text-davinci-003",
prompt,
max_tokens: 1025,
temperature: 0.7,
top_p: 1,
stream: true,
};
const completion = await openai.createCompletion ({
completionRequest,
});
message.channel.send(completion.choices[0].text);
} catch (error) {
if (error.response) {
console.log(error.response.status);
console.log(error.response.data);
} else {
console.log(error.message)
message.reply(error.response.data);
}
}
}
})