← all posts

How to Build a Roblox Friend Discord Bot With FriendPath

End-to-end tutorial: build a Discord bot that answers /friendpath user1 user2 with the degrees of separation between two Roblox accounts, in under 100 lines of code. We'll use discord.js v14 (the canonical Node.js Discord library) plus the FriendPath API. Working source code is included — you can copy-paste and have a running bot in 15 minutes.
Short answer
Build a Discord bot that answers /friendpath user1 user2 with the degrees of separation between two Roblox accounts. Uses discord.js v14 + the FriendPath Scan API (requires an API key from arbastro Suite — 50 free calls/day). Full working source code below — copy-paste, add your Discord token + FriendPath key, and you have a running bot in 15 minutes.

What you'll need

Step 0: Get your FriendPath API key

The FriendPath Scan API requires authentication. If you don't already have a key:

  1. Sign up at arbastro.com/signup
  2. Subscribe to arbastro Suite (30-day free trial)
  3. Go to arbastro.com/account/api-keys → Create key
  4. Copy the ak_live_... key — you only see it once, so store it somewhere safe

Step 1: Create the Discord bot application

  1. Go to the Discord Developer Portal
  2. Click "New Application", name it something like "FriendPath Bot"
  3. In the left sidebar, go to "Bot" → "Reset Token" → copy the token (you'll only see it once)
  4. Under "Bot" → "Privileged Gateway Intents" — leave them all off, we don't need any
  5. Under "OAuth2" → "URL Generator", check bot and applications.commands scopes, then under permissions check Send Messages and Use Slash Commands
  6. Copy the generated URL, paste it into your browser, and add the bot to your server

Step 2: Set up the project

mkdir friendpath-bot
cd friendpath-bot
npm init -y
npm install discord.js dotenv

Create a .env file with your Discord token and application ID (the app ID is on the application's main page on the Developer Portal):

DISCORD_TOKEN=your_bot_token_here
APPLICATION_ID=your_application_id_here
FRIENDPATH_KEY=ak_live_YOUR_FRIENDPATH_API_KEY

Step 3: Register the slash command

Create register.js:

require('dotenv').config();
const { REST, Routes, SlashCommandBuilder } = require('discord.js');

const command = new SlashCommandBuilder()
  .setName('friendpath')
  .setDescription('Find the degrees of separation between two Roblox players')
  .addStringOption(o => o.setName('from').setDescription('First Roblox username').setRequired(true))
  .addStringOption(o => o.setName('to').setDescription('Second Roblox username').setRequired(true));

const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
  await rest.put(
    Routes.applicationCommands(process.env.APPLICATION_ID),
    { body: [command.toJSON()] }
  );
  console.log('Slash command registered.');
})();

Run it once: node register.js. After a few seconds you'll see the /friendpath command in your Discord server.

Step 4: The actual bot

Create bot.js:

require('dotenv').config();
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

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

client.on('interactionCreate', async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName !== 'friendpath') return;

  const fromUser = interaction.options.getString('from');
  const toUser = interaction.options.getString('to');

  await interaction.deferReply();  // friendpath can take 30-60s

  try {
    const url = `https://arbastro.com/api/v1/friendpath/path?from=${encodeURIComponent(fromUser)}&to=${encodeURIComponent(toUser)}`;
    const resp = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.FRIENDPATH_KEY}` },
    });
    const data = await resp.json();

    if (!data.result) {
      await interaction.editReply(`No path found between **${fromUser}** and **${toUser}**. ${data.reason || ''}`);
      return;
    }

    const path = data.result.path.map(u => u.name).join(' → ');
    const embed = new EmbedBuilder()
      .setTitle(`${fromUser} ↔ ${toUser}`)
      .setDescription(`**${data.result.degrees} degrees of separation**\n\n\`${path}\``)
      .setFooter({ text: `Searched ${data.result.visited.toLocaleString()} accounts · friendpath.arbastro.com` })
      .setColor(0xC4956A);

    await interaction.editReply({ embeds: [embed] });
  } catch (err) {
    console.error(err);
    await interaction.editReply(`Error: ${err.message}`);
  }
});

client.login(process.env.DISCORD_TOKEN);

Run it: node bot.js. Type /friendpath builderman david.baszucki in your Discord server. You'll get an embed back with the path.

Step 5: Free hosting options

Running node bot.js works while your laptop is on, but you'll want to deploy somewhere 24/7. Options:

Rate limits to be aware of

The FriendPath public API endpoint is rate-limited per-IP. For a Discord bot serving one community of friends, this is fine. If your bot starts serving multiple busy servers, you'll want to:

Ideas for v2

Once the basic bot works, easy extensions:

What this is good for

Friend-path bots are great for content-creator servers, Roblox community Discords, friend groups that play together, and anyone running a "small world" challenge. The FriendPath API exposes everything the main website does, so anything you can do on friendpath.arbastro.com you can wrap in a slash command.

Full reference

Source code for this tutorial: github.com/arbastro/friendpath/examples (planned). Full API documentation: friendpath.arbastro.com/docs. The underlying algorithm explanation: How FriendPath Works: Bidirectional BFS Explained.

Read the FriendPath API docs

All endpoints, parameters, and live request runners.

Open the API docs →

Quick FAQ

What is FriendPath?

FriendPath is a free web tool that finds the shortest chain of friends between any two Roblox accounts using bidirectional breadth-first search over Roblox's public friends API. Runs in your browser, no install, no Roblox login required.

What does "degrees of separation" mean on Roblox?

It's the number of friend links between two accounts. If you're friends with someone who's friends with David Baszucki, you are 2 degrees of separation from David Baszucki. Most active Roblox players are within 3–5 hops of any famous account.

Is FriendPath free?

Yes. The web tool at friendpath.arbastro.com is 100% free, ad-supported. The public API offers 50 free calls per day with paid tiers beyond. See the API docs for details.

Does FriendPath work with banned or terminated accounts?

Yes — Roblox's friends API still returns friend lists for banned/terminated accounts, so FriendPath can traverse through them. The path is computed on the public friend graph, not on a player's active session.