I need help. Whenever I ask ChatGPT something on Discord, I get this error. What can I do?

The question is above 🙂

MISTAKE:

 OPENAI ERR: Error: Request failed with status code 429 ERR: TypeError: Cannot read properties of undefined (reading 'data')

CODE:

 require('dotenv/config'); const { Client, IntentsBitField } = require('discord.js'); const { Configuration, OpenAIApi } = require('openai'); const client = new Client({  intents: [    IntentsBitField.Flags.Guilds,    IntentsBitField.Flags.GuildMessages,    IntentsBitField.Flags.MessageContent,  ], }); client.on('ready', () => {  console.log('The bot is online!'); }); const configuration = new Configuration({  apiKey: process.env.API_KEY, }); const openai = new OpenAIApi(configuration); client.on('messageCreate', async (message) => {  if (message.author.bot) return;  if (message.channel.id !== process.env.CHANNEL_ID) return;  if (message.content.startsWith('!')) return;  let conversationLog = [    { role: 'system', content: 'You are a friendly chatbot.' },  ];  try {    await message.channel.sendTyping();    let prevMessages = await message.channel.messages.fetch({ limit: 15 });    prevMessages.reverse();       prevMessages.forEach((msg) => {      if (message.content.startsWith('!')) return;      if (msg.author.id !== client.user.id && message.author.bot) return;      if (msg.author.id == client.user.id) {        conversationLog.push({          role: 'assistant',          content: msg.content,          name: msg.author.username            .replace(/\s+/g, '_')            .replace(/[^\w\s]/gi, ''),        });      }      if (msg.author.id == message.author.id) {        conversationLog.push({          role: 'user',          content: msg.content,          name: message.author.username            .replace(/\s+/g, '_')            .replace(/[^\w\s]/gi, ''),        });      }    });       const result = await openai      .createChatCompletion({        model: 'gpt-3.5-turbo',        messages: conversationLog,        // max_tokens: 256, // limit token usage      })      .catch((error) => {        console.log(`OPENAI ERR: ${error}`);      });    message.reply(result.data.choices[0].message);  } catch (error) {    console.log(`ERR: ${error}`);  } }); client.login(process.env.TOKEN);
(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
5 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
iQa1x
1 year ago

429 is too many request, i.e. well, the thing is overloaded or the limit for the API key is reached.

iQa1x
1 year ago
Reply to  Stephano421

probably only use a paid account at openai…

iQa1x
1 year ago

The API access for unpaid accounts is somehow limited to 3/minute, if necessary this is not enough for Bot. So yes.