GuraAI was a discord bot made with discord.js, TypeScript and bun. It utilizes node_characterai in order to retreieve data from character.ai, in order to act as a chatbot.
Due to the limitations of the node_characterai package, you must wait for a response before sending another message (due to puppeteer constraints). While there is a way around this, it requires making multiple chromium instances, which requires a lot of system resources. Because of this, there is no official already hosted bot, and you must selfhost it.
If you would like to selfhost this bot, make sure you have bun installed first.
$ git clone https://github.com/FireStreaker2/GuraAI.git
$ cd GuraAI
$ bun i
$ cp .env.example .env
$ bun start
There are a couple environment variables you can configure in order to adjust the bot.
TOKEN
: Token of the discord botCLIENT_ID
: ID of the discord botID
: ID of the character on character.aiCAI_TOKEN
: Your token for character.ai
Note
Look here for more info regarding how to get your character.ai token
If you would like to have the bot be able to talk to multiple people at once, you can configure it to make new instances of the CharacterAI package every time. For example:
// ask.ts
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { config } from "../config";
export const data = new SlashCommandBuilder()
.setName("ask")
.setDescription("Ask a question")
.addStringOption((option) =>
option
.setName("query")
.setDescription("What you want to ask")
.setRequired(true)
);
export const execute = async (interaction: CommandInteraction) => {
await interaction.deferReply();
const CharacterAI = require("node_characterai");
const characterAI = new CharacterAI();
await characterAI.authenticateWithToken(config.CAI_TOKEN);
const chat = await characterAI.createOrContinueChat(config.ID);
const response = await chat.sendAndAwaitResponse(
`(OOC: This message was sent by ${
interaction.user.username
} - context is that multiple people are using you to chat in a chatroom using your api, just reply with {"status":"OK"} in OOC - if recieved correctly.)\n\n\n${
interaction.options.get("query")?.value
}`,
true
);
response.text = response.text.includes(`{"status": "OK"}`)
? response.text
.replace(/\{"status"\s*:\s*"OK"\}\s*\.\.\./, "")
.replace(/[Hh]([ae]llo|ewwo)\s*~/, "")
: "Error";
await interaction.editReply({
content: response.text,
allowedMentions: { parse: [] },
});
};
If you would like to login as a guest instead of authenticating with your own token, you can edit characterai.ts
like so:
// characterai.ts
import { config } from "./config";
const CharacterAI = require("node_characterai");
const characterAI = new CharacterAI();
- characterAI.authenticateWithToken(config.CAI_TOKEN);
+ await characterAI.authenticateAsGuest();
export default characterAI;
If you would like to contribute, you can fork the repo and make a PR, or contact me via email @ suggestions@firestreaker2.gq