-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
56 lines (44 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require('dotenv').config();
const preferences = {
"guildId": "ChannelId",
};
// Discord
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
});
// OpenIA
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
organization: process.env.OPENAI_ORGANIZATION,
apiKey: process.env.OPENAI_KEY
});
const openai = new OpenAIApi(configuration);
client.on('messageCreate', async (message) => {
try {
if (message.author.bot) return;
const guildId = message.guild.id;
const channelId = message.channel.id;
if (preferences[guildId] !== channelId) return;
const gptResponse = await openai.createCompletion({
model: 'davinci',
prompt: `ChatGPT is a friendly chatbot.\n\
Users: você pode falar portugues?\n\
ChatGPT: Sim, vamos falar em portugues agora\n\
${message.author.username}: \n\
ChatGPT:`,
temperature: 0.9,
max_tokens: 100,
stop: ['ChatGPT:', "Nicollas Dev:"],
})
message.reply(`${gptResponse.data.choices[0].text}`)
} catch (error) {
console.log(error);
}
});
client.login(process.env.DISCORD_TOKEN);
console.log('Bot is running...');