Bots (Multi-Platform)

NAIDE has built-in bot syntax for creating chatbots with minimal boilerplate. Supports Discord, Slack, Telegram, and LINE — events, message handling, and slash commands out of the box.

Basic Bot

bot myBot token "YOUR_BOT_TOKEN":
  on "ready":
    log "Bot is online!"

  on "message" (msg):
    if msg.content == "!ping":
      msg.reply("Pong!")

This compiles to discord.js (Node.js/Bun) or discord.py (Python).

Token from Environment

Use env to keep your token out of source code:

env:
  str DISCORD_TOKEN required

bot myBot token DISCORD_TOKEN:
  on "ready":
    log "Bot is online!"

Events

Use on blocks to handle Discord events:

bot myBot token TOKEN:
  on "ready":
    log "Connected!"

  on "message" (msg):
    if msg.content == "!hello":
      msg.reply("Hello!")

    if msg.content == "!time":
      msg.reply("Now: {Date.now()}")

The "message" event maps to messageCreate in discord.js and on_message in discord.py. Other event names are passed through as-is.

Slash Commands

Use slash blocks to register and handle slash commands:

bot myBot token TOKEN:
  slash "hello" "Says hello":
    interaction.reply("Hello!")

  slash "info" "Show bot info":
    interaction.reply("NAIDE Discord Bot v1.0")

Slash commands are automatically registered when the bot starts. The implicit parameter is interaction.

Custom Parameter Name

bot myBot token TOKEN:
  slash "greet" "Greets the user" (ctx):
    ctx.reply("Hi there!")

AI-Powered Bot

Combine with NAIDE's built-in ai module:

bot myBot token TOKEN:
  on "ready":
    log "AI Bot is online!"

  slash "ask" "Ask the AI a question" (interaction):
    str answer = await ai.ask(interaction.options.getString("question"))
    interaction.reply(answer)

  on "message" (msg):
    if msg.content.startsWith("!ai "):
      str prompt = msg.content.slice(4)
      str answer = await ai.ask(prompt)
      msg.reply(answer)

Slack Bot

Add type "slack" to create a Slack bot:

bot slackBot type "slack" token env.SLACK_TOKEN:
  on "message" (msg):
    msg.reply("Hi from Slack!")

  slash "deploy" "Deploy the app":
    respond("Deploying...")

Compiles to @slack/bolt (Node.js/Bun) or slack_bolt (Python).

Telegram Bot

Add type "telegram" for Telegram:

bot tgBot type "telegram" token env.TG_TOKEN:
  on "message" (msg):
    msg.reply("Hi from Telegram!")

  slash "start" "Start the bot":
    msg.reply("Welcome!")

Compiles to node-telegram-bot-api (Node.js/Bun) or python-telegram-bot (Python).

LINE Bot

Add type "line" for LINE Messaging API:

bot lineBot type "line" token env.LINE_TOKEN:
  on "message" (event):
    log event

Compiles to @line/bot-sdk (Node.js/Bun) or linebot (Python). Requires LINE_CHANNEL_SECRET env var for webhook verification.

Platform Comparison

Platform Node.js / Bun Python
Discord (default) discord.js discord.py
Slack @slack/bolt slack_bolt
Telegram node-telegram-bot-api python-telegram-bot
LINE @line/bot-sdk linebot

Multi-Target

Node.js (default)

$ naide bot.naide -o bot.mjs
$ node bot.mjs

Generates discord.js code. Install dependency:

$ npm install discord.js

Bun

$ naide bot.naide --target bun -o bot.mjs
$ bun bot.mjs

Also uses discord.js (compatible with Bun):

$ bun add discord.js

Python

$ naide bot.naide --target python -o bot.py
$ python bot.py

Generates discord.py code. Install dependency:

$ pip install discord.py

Generated Code

A simple bot like:

bot myBot token "TOKEN":
  on "ready":
    log "Ready!"
  slash "ping" "Pong!":
    interaction.reply("Pong!")

Compiles to (Node.js):

import { Client, GatewayIntentBits, REST, Routes, SlashCommandBuilder } from 'discord.js';

const myBot = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});

myBot.on('ready', () => {
  console.log("Ready!");
});

myBot.on('interactionCreate', async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName === "ping") {
    interaction.reply("Pong!");
  }
});

myBot.once('ready', async () => {
  const commands = [
    new SlashCommandBuilder().setName("ping").setDescription("Pong!"),
  ];
  const rest = new REST().setToken("TOKEN");
  await rest.put(Routes.applicationCommands(myBot.user.id), { body: commands });
});

myBot.login("TOKEN");