Generation

generate functionSat, 29 Apr 2023

in node.js, and discord.js v14, generate a fuction to add the OpenAI API in a Discord Bot

const { Client } = require('discord.js'); const client = new Client(); const OpenAi = require('openai'); const openAI = new OpenAi(process.env.OPENAI_KEY); client.on('message', async msg => { if(msg.content.startsWith('!generate')){ const message = msg.content.split(' ').slice(1).join(' '); openAI.completions({ prompt: message, max_tokens: 100, temperature: 0.6, top_p: 0.9, n: 3 }).then((res) => { msg.channel.send(res.choices[0].text); }); } });

Javascript
Generate More

Want to kickstart your project?Use the new AI Studio to create your code