Quickstart
Get up and running with the Fluxer API quickly
This guide walks you through building a tiny Fluxer bot using JavaScript. Fluxer works with any language that can speak HTTP, but JavaScript keeps the examples short and familiar.
Fluxer's API is intentionally close to the Discord API. If you've built Discord bots before, you'll recognize most of the shapes here. In fact, many Discord libraries work with Fluxer with only a few tweaks.
For this quickstart, we'll use discord.js and its core packages:
Prerequisites
Before you start, make sure you have:
- Node.js installed (a reasonably recent LTS version is fine)
- A Fluxer account (sign up at https://web.fluxer.app/register)
- A text editor or IDE (for example, VS Code)
- Basic familiarity with JavaScript and Node.js
Step 1: Set Up Your Project
- Create a new directory and move into it:
mkdir fluxer-quickstart cd fluxer-quickstart - Initialize a new Node.js project:
echo '{ "name": "fluxer-quickstart", "version": "1.0.0", "type": "module", "main": "bot.js" }' > package.json - Install the required packages:
npm install @discordjs/core @discordjs/rest @discordjs/ws
Step 2: Create a Fluxer Application
- Open the Fluxer web or desktop app and log in.
- Press the cogwheel in the bottom-left to open User Settings, then go to Developer Applications.
- Create a new application. Name it something awesome.
- Generate a bot token for that application and copy it somewhere safe — we'll use it as
FLUXER_BOT_TOKEN. - Press "Invite Bot" and select a community where you have the "Manage Community" permission.
Step 3: Write Your Bot Code
Create a file named bot.js in your project directory and add:
import {Client, GatewayDispatchEvents} from '@discordjs/core';
import {REST} from '@discordjs/rest';
import {WebSocketManager} from '@discordjs/ws';
const rest = new REST({api: 'https://api.fluxer.app', version: '1'}).setToken(process.env.FLUXER_BOT_TOKEN);
const gateway = new WebSocketManager({
intents: 0,
rest,
token: process.env.FLUXER_BOT_TOKEN,
version: '1',
});
export const client = new Client({rest, gateway});
client.on(GatewayDispatchEvents.MessageCreate, async ({api, data}) => {
if (data.content === 'ping') {
await api.channels.createMessage(data.channel_id, {
content: 'pong',
});
}
});
client.on(GatewayDispatchEvents.Ready, (data) => {
console.log(`Logged in as ${data.user.username}#${data.user.discriminator}`);
});
gateway.connect();This does three things:
- Connects to the Fluxer gateway using your bot token
- Listens for new messages
- Replies with
pongwhenever someone sendspingin a channel your bot can see
Step 4: Run Your Bot
- Set your bot token as an environment variable.
On macOS/Linux:
On Windows (Command Prompt):export FLUXER_BOT_TOKEN="your_bot_token_here"set FLUXER_BOT_TOKEN="your_bot_token_here" - Start the bot:
node bot.js
If everything is wired up correctly, you should see a log line with your bot's username. Try sending ping in a channel where the bot has access — it should answer with pong.
Pat Yourself on the Back
Nice work. You've just:
- Created a Fluxer application
- Wired up discord.js core packages to talk to the Fluxer API
- Built and run a simple message-handling bot
From here, you can:
- Browse the Fluxer API reference
- Explore all events in the Gateway Events documentation
- See what other API endpoints are available
- Start adding commands, routing, and whatever else your bot needs
Happy coding!