LittleSpace Network Developers
Sign in

Getting started

By the end of this page you’ll have a bot running on your computer that answers !ping in a littlespace.chat channel.

#Create the bot account

  1. Open littlespace.chat and click the cog at the bottom left to open User Settings.
  2. Go to Applications and create a new application. The name you give it is the name people will see on the bot.
  3. Copy the bot token and keep it somewhere safe. You’ll only see it once.
  4. Copy the application ID too. You need it for the invite link.

#Invite it to a community

Open the invite link builder, paste your application ID and pick Chat bot. Open the link it makes, choose a community and approve it. You need Manage community in that community, or an owner can open the link for you.

The bot shows up in the member list as offline. That’s expected until your code is running.

#Make the project

The quickest way is the starter, which sets up a folder with everything in place:

Terminal
npm create @littlespace/bot@latest my-bot
cd my-bot

It asks for your token and saves it in a .env file that’s already left out of git.

If you’d rather set it up by hand:

Terminal
mkdir my-bot
cd my-bot
npm init -y
npm pkg set type=module
npm install @littlespace/fluxkit

Then make a file called .env with your token in it:

.env
FLUXER_TOKEN=paste-your-token-here

#Write the bot

Create bot.js:

JavaScript
import { FluxerClient } from '@littlespace/fluxkit';

const bot = new FluxerClient({
  instance: 'https://littlespace.chat',
  token: process.env.FLUXER_TOKEN,
});

bot.command('ping', ({ reply }) => reply('pong!'));

bot.on('ready', () => console.log(`Logged in as ${bot.user.username}`));

await bot.login();

#Run it

Terminal
node --env-file=.env bot.js

You should see Logged in as and your bot’s name. Type !ping in a channel the bot can see, and it replies pong!.

#If it doesn’t work

What you seeWhat to do
gateway closed 4004: invalid bot tokenThe token is wrong or was reset. Copy it again from Applications.
It logs in but doesn’t answerCheck the bot can view and send messages in that channel. Channel permissions can hide it even when the role allows it.
Authorization failed: Missing client_id when invitingThe invite link is missing its application ID. Make it again with the invite link builder.
--env-file isn’t recognizedYour Node.js is older than 20. Update it, or set the token in your terminal instead.

#Next