GPTcord/src/index.ts

34 lines
914 B
TypeScript
Raw Normal View History

2023-03-14 21:16:54 +01:00
import DiscordApi from "discord.js";
import { Configuration as OpenAIApiConfiguration, OpenAIApi } from "openai";
import { PrismaClient } from "@prisma/client";
2023-03-14 21:16:54 +01:00
import config from "./config";
import { queueRequest } from "./execution";
2023-03-14 21:16:54 +01:00
const discord = new DiscordApi.Client({
intents: [
DiscordApi.GatewayIntentBits.Guilds,
DiscordApi.GatewayIntentBits.GuildMessages,
DiscordApi.GatewayIntentBits.MessageContent,
]
});
export const openai = new OpenAIApi(new OpenAIApiConfiguration({
2023-03-14 21:16:54 +01:00
apiKey: config.tokens.OpenAI
}));
export const database = new PrismaClient();
2023-03-14 21:16:54 +01:00
discord.on("ready", async event => {
console.log(`Connected to Discord as ${event.user.tag} (${event.user.id})`);
});
discord.on("messageCreate", async message => {
if (message.author.bot) return;
if (!message.mentions.has(message.client.user)) return;
queueRequest(message);
});
2023-03-14 21:16:54 +01:00
discord.login(config.tokens.Discord);