Skip to content

Elitezen/discordjs-chatgpt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

discordjs-chatgpt

screenshot

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'
});