discordjs-chatgpt
v0.2.1
Published
A small module for quick implemntation of OpenAI's Chat-GPT into Discord.JS
Downloads
115
Maintainers
Readme
discordjs-chatgpt
A small module for quick implemntation of OpenAI's Chat-GPT into Discord.JS. This is the first public version of the library. For bug reports or feature requests visit https://github.com/Elitezen/discordjs-chatgpt
This module requires an OpenAI API key. You can get one here
Updates
0.2.1
Added gaurd to text length in embeds
Installing
npm i discordjs-chatgpt
Example Usage
Interaction
const { SlashCommandBuilder } = require('discord.js');
const { ChatGPTClient } = require('discordjs-chatgpt');
const chatgpt = new ChatGPTClient('YOUR_OPENAI_API_KEY');
module.exports = {
data: new SlashCommandBuilder()
.setName('chatgpt')
.setDescription('Talk with Chat-GPT!')
.addStringOption(option =>
option
.setName('message')
.setDescription('Your message')),
async execute(interaction) {
const msg = interaction.options.getString('message', true);
await chatgpt.chatInteraction(interaction, msg);
}
};
Message
Filter messages and clean message.content
as needed.
const { Events } = require('discord.js');
const { ChatGPTClient } = require('discordjs-chatgpt');
const chatgpt = new ChatGPTClient('YOUR_OPENAI_API_KEY');
const examplePrefix = "!";
module.exports = {
name: Events.MessageCreate,
once: false,
execute(message) {
const msg = message.content.replace(examplePrefix, '');
return await chatgpt.chatMessage(message, msg);
},
};
Options
You can toggle context remebering, and response type.
const chatgpt = new ChatGPTClient('YOUR_OPENAI_API_KEY', {
contextRemembering: true,
responseType: 'embed' // or 'string'
});