Ask anything, generate any fake story/script,etc., possibilities are endless. ••• Use !gpt <query> . ••• But at first, you'll need openai's API key which you can get from here- ••• https://beta.openai.com/account/api-keys ••• you'll be asked to enter it when installing the snippet.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const openai_api_key = process.env.OPENAI_KEY;
const prompt = context.params.event.content.split(' ').slice(1).join(' ');
await lib.discord.channels['@0.3.2'].typing.create({
channel_id: `${context.params.event.channel_id}`,
});
try {
let request = await lib.http.request['@1.1.7']({
method: 'POST',
url: 'https://api.openai.com/v1/completions',
headers: {
'Content-Type': `application/json`,
Authorization: `Bearer ${openai_api_key}`,
},
body: JSON.stringify({
model: 'text-davinci-003',
prompt: `${prompt}`,
max_tokens: 2048,
temperature: 1,
}),
});
const octetStream = new Uint8Array(request.body);
const decoder = new TextDecoder();
const text = decoder.decode(octetStream);
let json = JSON.parse(text);
let answer = json.choices[0].text;
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
embed: {
type: 'rich',
description: `${answer}`,
color: 0xff0000,
},
message_reference: {
message_id: `${context.params.event.id}`,
},
});
} catch (e) {
console.log(e);
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: context.params.event.channel_id,
content: '', // required
tts: false,
embed: {
type: 'rich',
title: 'Something went wrong please try again later',
description: `\`${e.message}\``,
color: 0xff0000,
},
message_reference: {
message_id: context.params.event.id,
},
});
}