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
- Open littlespace.chat and click the cog at the bottom left to open User Settings.
- Go to Applications and create a new application. The name you give it is the name people will see on the bot.
- Copy the bot token and keep it somewhere safe. You’ll only see it once.
- 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:
npm create @littlespace/bot@latest my-bot
cd my-botIt 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:
mkdir my-bot
cd my-bot
npm init -y
npm pkg set type=module
npm install @littlespace/fluxkitThen make a file called .env with your token in it:
FLUXER_TOKEN=paste-your-token-here#Write the bot
Create bot.js:
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
node --env-file=.env bot.jsYou 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 see | What to do |
|---|---|
gateway closed 4004: invalid bot token | The token is wrong or was reset. Copy it again from Applications. |
| It logs in but doesn’t answer | Check 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 inviting | The invite link is missing its application ID. Make it again with the invite link builder. |
--env-file isn’t recognized | Your Node.js is older than 20. Update it, or set the token in your terminal instead. |
#Next
- Commands: arguments, aliases and who can use what
- Sending messages: embeds, reactions and DMs
- Running your bot 24/7: keep it online after you close the terminal