require('dotenv').config();
const { Client, GatewayIntents, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const got = require('got');
client.on('messageCreate', async (message) => {
try {
if (message.author.bot) return;
const url = 'https://api.openai.com/v1/engines/davinci/completions';
const prompt = `User: ${message.content}\n`;
const params = {
prompt: prompt,
max_tokens: 100,
temperature: 0.7,
};
const headers = {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json',
};
const response = await got.post(url, { json: params, headers: headers }).json();
const reply = response.choices[0].text.trim();
message.reply(reply);
} catch (err) {
console.error(err);
}
});
client.login(process.env.DISCORD_TOKEN);
console.log('Discord bot is online.');
here is the new code
HTTPError: Response code 429 (Too Many Requests)
at Request.<anonymous> (D:\ChatGBT-discord-bot\node_modules\got\dist\source\as-promise\index.js:118:42)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_NON_2XX_3XX_RESPONSE',
timings: {
start: 1685482297320,
socket: 1685482297321,
lookup: 1685482297345,
connect: 1685482297379,
secureConnect: 1685482297415,
upload: 1685482297415,
response: 1685482297578,
end: 1685482297580,
error: undefined,
abort: undefined,
phases: {
wait: 1,
dns: 24,
tcp: 34,
tls: 36,
request: 0,
firstByte: 163,
download: 2,
total: 260
}
}
}
here is the new error
Well at least im not getting a Key error anymore but now im getting error code 429 i tried adding a limiter but that hasnt gotten me too far either. Any new suggestions?