Build a Bible verse Discord bot
This guide builds a Discord bot with a /verse command. Type /verse ref:John 3:16 in your server and the bot replies with the passage and its attribution.
Uses a secret key (bva_sk_…), because the code runs on a server.
1. What you need
A Discord application with a bot token (from the Discord Developer Portal), your application ID, Node.js 18 or later, and a Bible Verse API secret key (bva_sk_). The bot runs on your server, so a secret key is the right choice.
Install discord.js with npm install discord.js.
2. The bot
import { Client, Events, GatewayIntentBits, MessageFlags, REST, Routes, SlashCommandBuilder } from "discord.js";
const API = "https://api.bibleverse-api.com/v1";
const { DISCORD_TOKEN, DISCORD_APP_ID, BIBLE_API_KEY } = process.env;
const command = new SlashCommandBuilder()
.setName("verse")
.setDescription("Show a Bible passage")
.addStringOption((o) => o.setName("ref").setDescription("For example: John 3:16").setRequired(true));
// Register the /verse command (safe to run on every start).
await new REST().setToken(DISCORD_TOKEN).put(Routes.applicationCommands(DISCORD_APP_ID), { body: [command.toJSON()] });
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== "verse") return;
const ref = interaction.options.getString("ref", true);
const res = await fetch(`${API}/bibles/kjv/passages?format=text&ref=${encodeURIComponent(ref)}`, {
headers: { Authorization: `Bearer ${BIBLE_API_KEY}` },
});
if (!res.ok) {
const { error } = await res.json();
return interaction.reply({ content: error.message, flags: MessageFlags.Ephemeral });
}
const text = await res.text();
await interaction.reply(text.slice(0, 2000)); // Discord messages are limited to 2,000 characters
});
client.login(DISCORD_TOKEN);3. Run it
Set DISCORD_TOKEN, DISCORD_APP_ID and BIBLE_API_KEY, then run node bot.mjs. Invite the bot to your server with the applications.commands scope, and try /verse ref:Psalm 23.
Misspelled references reply privately with a suggestion, for example “Did you mean John?”.
Ready to try it?
The Free plan gives you 5,000 requests and 2,000 verses a day, with no card.