Getting started
This page shows you how to quickly get started with clashai.js
Installing
Node.JS 14.x or higher is required.
npm install clashai.js
You can also install the latest version from GitHub. Note that this version might be unstable.
npm install git+github.com/verleihernix/clashai.js.git
First Steps
You should already have a basic understanding of JavaScript or TypeScript.
Generate an api key in the ClashAI Discord using
/manage_key
.Create a new Client using the Client class.
Example
A quick example of how clashai.js works
TypeScript
import { Client, Messages } from 'clashai.js'; const client = new Client('your-api-key', 'gpt-4o'); client.on('error', err => { // client.on('error', console.log); console.log(err.message); }); client.on("requestMade", info => { // client.on('requestMade', console.log); console.log(info); }); const messages: Messages[] = [ { role: 'user', content: 'Hello, how are you?' }, { role: 'system', content: 'You are a friendly chatbot developed in typescript with the ClashAI Api. You use emojis in your answers.' } ]; const main: () => Promise<void> = async () => { const response = await client.makeRequest(messages); console.log(response?.choices[0].message.content); }; // async function main() main();
JavaScript
const ClashAI = require('clashai.js'); // const { Client } = require('clashai.js'); const client = new ClashAI.Client('your-api-key', 'gpt-4'); client.on('error', console.log); client.on('requestMade', console.log); const main = async () => { const response = await client.makeRequest([ { role: 'system', content: 'You are a friendly chatbot developed in typescript with the ClashAI Api. You use emojis in your answers.', }, { role: 'user', content: 'Hello, how are you?' } ]); console.log(response.choices[0].message.content); }; // async function main() main();
Last updated