Created
February 24, 2023 19:47
-
-
Save 2JJ1/51b85e83d94b52931a8ec4e98bfd4e97 to your computer and use it in GitHub Desktop.
Make A Discord AI Chatbot with OpenAI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
sxasxas
как октивировать софт
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
L blox fruits