Skip to content

Instantly share code, notes, and snippets.

@2JJ1
Created February 24, 2023 19:47
Show Gist options
  • Save 2JJ1/51b85e83d94b52931a8ec4e98bfd4e97 to your computer and use it in GitHub Desktop.
Save 2JJ1/51b85e83d94b52931a8ec4e98bfd4e97 to your computer and use it in GitHub Desktop.
Make A Discord AI Chatbot with OpenAI
let DiscordBotAPIKey = "YOURKEYHERE"
let OpenAIAPIKey = "YOURKEYHERE"
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: OpenAIAPIKey,
});
const openai = new OpenAIApi(configuration);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", async (msg) => {
if(msg.author.bot) return
if(!msg.mentions.has(client.user)) return
msg.content = msg.content.replace(/<@\d+>/g, "")
let response = await msg.reply("Generating response...")
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: msg.content,
max_tokens: 100,
user: msg.author.id.toString(),
});
response.edit(completion.data.choices[0].text)
})
client.login(DiscordBotAPIKey)
@minksW
Copy link

minksW commented Jul 20, 2023

L blox fruits

@maksimaka2012
Copy link

sxasxas

@maksimaka2012
Copy link

как октивировать софт

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment