1.1.2 • Published 1 year ago
discordai v1.1.2
DiscordGPT
Notes
This project is still in beta, and has bugs.
discordGPT Installation
$ npm install discordgpt
Usage
DiscordGPT can implement AI features into your Discord bot by just a few simple steps.
Create an OpenAI API key here if you do not have an api key.
Install discordGPT
- Implement this example code:
const { discordGPT } = require("discordgpt");
const { Client } = require("discord.js");
const secret = require("../config.json");
const client = new Client({ intents: [] });
const prompt = "";
new discordGPT(client, {
message: prompt,
apiKey: secret,
});
- Make an config.json (or an .env file) and put your OpenAI API key there.
{
apiKey: "API_KEY_HERE"
}
- Finally, you can place that in a discord bot command.
Example:
const { SlashCommandBuilder } = require("discord.js");
const { discordGPT } = require("discordgpt");
module.exports = {
data: new SlashCommandBuilder()
.setName("ask-gpt")
.setDescription("Generate a AI response!")
.addStringOption((option) =>
option
.setName("prompt")
.setDescription("The text to generate.")
.setRequired(true)
),
async execute(client, interaction) {
const prompt = interaction.options.getString("prompt");
const gpt = new discordGPT(client, {
message: prompt,
apiKey: secret,
});
await interaction.reply({ content: gpt.response });
},
};