Najova

DocsExtensions

discord.najova0.0.7

Official Najova Extension

Discord bots in Najova: slash commands, prefix commands, buttons, members, reactions and bot variables.

discord.najova

Discord bots in Najova (.naja). In the Najova IDE: paste the bot's token in the Bot tab, make a script from the Discord bot template (New script), then Start bot. From a terminal: najova run bot.naja with the token in DISCORD_TOKEN. The first run asks to allow what it needs (network, Node).

The short style (0.0.5): each command is a block, and inside it the names work as they did in the Construct app. Every function is listed under Functions in discord below.

$use[discord]
$slash[daily;Get 10 coins]
  $setMemberVar[coins;$getMemberVar[coins] + 10]
  $reply[$username now has $getMemberVar[coins] coins.]
$endslash

$slash[give;Give coins to another member]
  $slashOption[member;user;Who gets the coins]
  $slashOption[amount;whole;How many]
  $onlyIf[$option[amount] > 0;Give at least 1 coin.]
  $onlyIf[$option[member] != $authorID;You can't give coins to yourself.]
  $if[$getMemberVar[coins] >= $option[amount]]
    $setMemberVar[coins;$getMemberVar[coins] - $option[amount]]
    $setMemberVar[coins;$getMemberVar[coins;$option[member]] + $option[amount];$option[member]]
    $reply[$userMention gave $option[amount] coins to $userMention[$option[member]].]
  $else
    $reply[You only have $getMemberVar[coins] coins.]
    $ephemeral
  $endif
$endslash

$prefix[hi]
  $prefixAlias[hello]
  $reply[Hello $username, welcome to $serverName!]
$endprefix

$event[join]
  $print[$username joined]
$endevent

$start[$env[DISCORD_TOKEN]]
  • Blocks: $slash[name;description] with $slashOption[name;type;what it is for;optional] lines at its top (types text, whole, number, yesno, user, channel, role); $prefix[name] with $prefixAlias[other] lines; $event[name] for ready, message, join, leave, reaction and button.
  • In a block: what $reply says is sent once, when the block ends; $ephemeral makes it private; $onlyIf[condition;message] stops the block when the condition does not hold. $option, $username, $authorID, $message, $argCount, $customID, $emoji and the others tell about the event.
  • Variables: $getMemberVar / $setMemberVar (a person in this server), $getUserVar / $setUserVar (a person anywhere), $getServerVar / $setServerVar, $getGlobalVar / $setGlobalVar. An unset one is 0.

The long style (from 0.0.1) keeps working beside it:

$use[discord]
$call[discord.slash;give;Give coins to a member;member:user;amount:whole?]
$on[discord.Slash;cmd]
  $if[$get[cmd.name] == "give"]
    $call[discord.reply;$get[cmd];$table[content;Done!;private;true]]
  $endif
$endon
$call[discord.start;$env[DISCORD_TOKEN]]
  • Events: Ready (bot), Message (text, command, args, user, server, channel, mentions), Slash (name, options), Button (id), Join, Leave, Reaction (emoji). Each event's table can be passed back as "where" ($get[cmd]); it is good for 15 minutes.
  • Calls: start (token; options table: prefix, server, intents, status, activity), stop, slash (name; description; options as name:type with ? when it may be left out; types text, whole, number, yesno, user, channel, role), reply, send (a channel id or a where), dm, react, deleteMessage, addRole / removeRole / setNick (where; user id; role or nick), user (id; where), getVar (scope user, member, server or global; name; where; what to give back when it was never set, "" if left out: say 0 for a count) / setVar (scope; name; value; where), ping, shards (one table per shard: id, state, ping, servers), embed (title; description; colour: a name like purple, or #9b59b6; gives a whole message, or put it in a message's embed), button (label; id; style blue/grey/green/red, or a link).
  • Messages: text, or $table[content;...;embed;$table[title;...];buttons;$list[...];files;$list[...];private;true]. files are files in the bot's folder (pictures from the canvas package, say).
  • Commands in many files: name a slash command at the top of any file; start registers them all at once. Called later (in Ready, say), they still go out together in one registration.
  • 0.0.2: can (where; permission like ModerateMembers; person), timeout (where; person; minutes, 0 ends it; reason), part (a package's Node part, used by packages).

Sharding

Discord makes a bot in 2,500 servers or more split its connection into shards. The bot runs every shard itself: commands, events and variables work as before. DISCORD_SHARDS (the Sharding page on Home in Najova IDE, or shards in start's options) is auto (the default: Discord says how many) or a number from 1 to 64. $call[discord.shards] lists the shards; an event's server table has its shard.

A project in folders

New project in the Najova IDE makes this layout (from ide/project); the bot starts from index.naja:

index.naja     $use[discord], one $use line per script below (the IDE keeps these), then discord.start
slash/         slash commands; a file may hold several
prefix/        prefix commands
events/        Ready, Join, Leave, Reaction, Button, Message
modules/       scripts you share: $use[tools]
packages/      packages for the whole bot: every file knows them by name, without $use

Packages

Extra parts for a bot. Switch one on for your project on the Packages page in Najova IDE (Home > Packages): what it adds then works with $use[discord] alone, and its settings are on that page too. The IDE keeps the switch in the project's najova.json ("packages": { "discord.najova": ["xp"] }), so the bot runs the same way on Nylon Hosting.

PackageAdds
xpXP and levels from chatting, level-up messages, role rewards, /rank: $xpOf, $level, $xpStats, $giveXp, $levelReward
moderation/warn, /warnings, /timeout, /clearwarnings for moderators, a log channel: $warnMember, $warningsOf, $clearWarnings, $timeoutMember, $modLog
canvasWelcome and rank cards as pictures: $welcomeCard, $rankCard (needs npm install in its folder)
nhsFor bots on Nylon Hosting: $nhsHosted, $nhsCredits, $nhsKeep, $nhsRead, $nhsLog

Two packages that add the same name can't both be on: the run stops and names both. Bots made before 0.0.7, with $use[discord/NAME] and $call[xp.rankCommand], keep working.

Making a package

A package is a folder in packages/ with:

  • extension.json: "id": "discord.najova/NAME", "name", "title", "version", "entry": "main.naja", "requires": { "discord.najova": ">=0.0.7" }, "adds": ["myFunction", "block_myblock"] (the names it puts into discord; block_x makes a $x ... $endx block), and optionally "ide": { "panel": "ide/panel.json" }.
  • main.naja: it starts with $use[discord] and makes each name in adds with $function. A $-- usage: $name[a;b] line above a function is what the IDE's Functions list and Docs show. Inside a block, $context gives the command or event (c.event), so a function needs no "where" value.
  • ide/panel.json (optional): { "fields": [ { "id", "label", "env", "placeholder", "help" } ] }, the settings shown in its card on the Packages page. The bot gets each one as the env value named by env (read it with $env[NAME]).
  • README.md.

A name in adds must not be one discord already has ($timeout, $reply ...) or one the package's own name takes (the package xp can't add $xp): najova.exe stops with the reason.

  • On Nylon Hosting bots run with --safe: files only inside the bot's folder, and $fetch is off (Discord and the packages work as usual).
  • Variables are kept in discord-variables.json next to the bot, in the same form as the Construct app's.

Bots from the old Construct app

Open a .construct, .const or .conca file in the Najova IDE and pick Convert, or run node convert/convert.mjs <bot.construct | script.const | script.conca>. It asks first, keeps a .bak copy, writes <bot>.naja and legacy.naja, and lists what it could not convert.

For extension makers

The extension is a folder: extension.json, main.naja (what $use[discord] gives) and helper.mjs, a Node program on discord.js (Apache-2.0) that najova.exe starts and talks to over stdin/stdout (exodia/construct_cli/construct_helpers.h). It needs Node.js and, once, npm install in this folder (the Najova installer does both). ide/panel.json is the Bot tab and ide/templates/ the New script templates. The IDE's Docs list each shared function of main.naja (and of each package) with the $-- lines right above it as its help; a $-- usage: ... line there gives how it is written. Give every new shared function such a line (the IDE's tests check it).

Check: node check/run.mjs runs check/bot.naja on the Construct app's mock gateway and plays check/play.json, then converts the app's Starter bot (check/convert/) and plays that too (no network; never real Discord).

Functions

discord.start

$start[$env[DISCORD_TOKEN]]

Logs the bot in and starts it; the slash commands named so far are registered then. Give the token from the environment, never in the script.

discord.stop

$call[discord.stop]

Logs the bot out and ends the script.

discord.slash

$call[discord.slash;give;Give coins;member:user;amount:whole?]

A slash command in the long style: its name, what it does, then up to 8 options as name:type (a ? at the end makes it optional). A $slash block does this for you.

discord.send

$call[discord.send;channel;message]

Sends a message (text, or a table made with $embed, with buttons) to a channel: its id, or an event for that event's channel.

discord.dm

$call[discord.dm;person;message]

Sends a private message to a person (their id, or the person of the event).

discord.react

$call[discord.react;to;emoji]

Adds an emoji reaction to the message of a Message or Reaction event.

discord.deleteMessage

$call[discord.deleteMessage;to]

Deletes the message of a Message or Reaction event.

discord.addRole

$call[discord.addRole;where;person;role]

Gives a person a role (by its name) in the server of the event.

discord.removeRole

$call[discord.removeRole;where;person;role]

Takes a role (by its name) away from a person in the server of the event.

discord.setNick

$call[discord.setNick;where;person;nick]

Sets a person's nickname in the server of the event ("" puts back their own name).

discord.user

$call[discord.user;id;where]

A table about a person: id, name, nick, mention, avatar, created, joined, roles and bot (yes for a bot).

discord.getVar

$call[discord.getVar;scope;name;where;fallback]

A kept variable: scope member, user, server or global; where is the event (or nil for global). fallback: what to give back when the variable was never set ("" if left out), say 0 for a count.

discord.setVar

$call[discord.setVar;scope;name;value;where]

Keeps a variable (scope member, user, server or global) in discord-variables.json, so it stays after a restart.

discord.ping

$call[discord.ping]

How long Discord takes to answer the bot, in milliseconds.

discord.shards

$each[s;$call[discord.shards]] $print[$get[s.id]: $get[s.servers] servers] $endeach

The bot's shards, one table each: id, state (ready, connecting, reconnecting ...), ping and servers. A bot in fewer than 2,500 servers has one. An event's server table has the shard it came on.

discord.embed

$call[discord.embed;title;description;color]

A message with an embed: a title, its text and a colour (#5865f2, or a number).

discord.button

$call[discord.button;label;id;style]

A button for a message: its label, its id ($event[button] blocks get it) and style (blue, grey, green or red). A link button is a table with label and url.

discord.bot

$call[discord.bot]

A table about the bot itself: id and name.

discord.can

$call[discord.can;where;permission;person]

yes when the person (or the person of the event) has a permission in the server, such as ManageMessages or ModerateMembers.

discord.timeout

$call[discord.timeout;where;person;minutes;reason]

Times a person out for some minutes, with a reason (0 minutes ends a timeout).

discord.part

$call[discord.part;package;name;a;b;c;d;e;f]

Runs a function of a package's Node part (for package makers): the package, the function and up to 6 values.

$slashBlock

$slash[give;Give coins to a member] $slashOption[amount;whole;How many] ... $endslash

A slash command as a block. $slashOption lines at its top name its options: name, type (text, whole, number, yesno, user, channel, role), what it is for, and "optional". The lines inside run each time someone uses the command.

$prefixBlock

$prefix[ping] $prefixAlias[p] ... $endprefix

A prefix command as a block, such as !ping. $prefixAlias lines at its top give it more names. $message and $argCount give the words after it.

$eventBlock

$event[join] ... $endevent

Lines that run on an event: ready, message, join, leave, reaction or button.

discord.reply

$reply[text]

In a block: says text, sent once when the block ends. Anywhere: $call[discord.reply;event;message] answers that event at once.

discord.ephemeral

$call[discord.ephemeral]

Makes what the block says private: only the person who used the command sees it (slash commands and buttons).

discord.onlyIf

$call[discord.onlyIf;condition;message]

Goes on only when the condition holds; else says the message (if any, privately, as the Construct app did) and stops the block. What the block said before goes first, as it was.

discord.customID

$call[discord.customID]

The id of the button that was pressed ($event[button] blocks).

discord.emoji

$call[discord.emoji]

The emoji of a reaction ($event[reaction] blocks).

discord.option

$call[discord.option;name]

The value given for a slash command's option, by its name ("" when it was left out).

discord.authorID

$call[discord.authorID]

The id of the person who used the command or caused the event.

discord.username

$call[discord.username;id]

A person's user name: the person of the event, or the id given.

discord.displayName

$call[discord.displayName;id]

A person's name in this server (their nickname, or else their name).

discord.userMention

$call[discord.userMention;id]

A mention of a person (<@id>) that pings them in a message.

discord.userAvatar

$call[discord.userAvatar;id]

The link to a person's avatar picture.

discord.serverName

$call[discord.serverName]

The name of the server of the event ("" in a private message).

discord.guildID

$call[discord.guildID]

The id of the server of the event ("" in a private message).

discord.channelID

$call[discord.channelID]

The id of the channel of the event.

discord.channelName

$call[discord.channelName]

The name of the channel of the event.

discord.commandName

$call[discord.commandName]

The name of the command that is running.

discord.message

$call[discord.message;n]

A prefix command's words after the command: all of them, or word n (1 = first).

discord.argCount

$call[discord.argCount]

How many words came after a prefix command.

discord.getMemberVar

$call[discord.getMemberVar;name;user;default]

A variable kept for a member (a person in this server): the person of the event, or the id given. An unset one is 0, or the default given.

discord.setMemberVar

$call[discord.setMemberVar;name;value;user]

Keeps a variable for a member (a person in this server): the person of the event, or the id given.

discord.getUserVar

$call[discord.getUserVar;name;user;default]

A variable kept for a person in every server: the person of the event, or the id given. An unset one is 0, or the default given.

discord.setUserVar

$call[discord.setUserVar;name;value;user]

Keeps a variable for a person in every server.

discord.getServerVar

$call[discord.getServerVar;name;default]

A variable kept for this server. An unset one is 0, or the default given.

discord.setServerVar

$call[discord.setServerVar;name;value]

Keeps a variable for this server.

discord.getGlobalVar

$call[discord.getGlobalVar;name;default]

A variable kept for the whole bot. An unset one is 0, or the default given.

discord.setGlobalVar

$call[discord.setGlobalVar;name;value]

Keeps a variable for the whole bot.

discord.botName

$call[discord.botName]

The bot's own name.

discord.botID

$call[discord.botID]

The bot's own id.

Packages

  • discord.najova/canvas0.0.2Package

    Welcome and rank cards as pictures: the member's avatar, name and level, in your colours.

    NylonLabsOfficial Najova PackageUpdated 23 Nov 2026Needs discord.najova

    Downloads
    0
    Views
    0
  • discord.najova/moderation0.0.2Package

    Warnings, timeouts and a log channel: /warn, /warnings, /timeout and /clearwarnings for moderators.

    NylonLabsOfficial Najova PackageUpdated 23 Nov 2026Needs discord.najova

    Downloads
    0
    Views
    0
  • discord.najova/nhs0.0.2Package

    For bots hosted on Nylon Hosting: is it hosted, NHS Credits left, values kept across restarts, and a log line.

    NylonLabsOfficial Najova PackageUpdated 23 Nov 2026Needs discord.najova

    Downloads
    0
    Views
    0
  • discord.najova/xp0.0.2Package

    Levels from chatting: XP per message, level-up messages, role rewards and /rank.

    NylonLabsOfficial Najova PackageUpdated 23 Nov 2026Needs discord.najova

    Downloads
    0
    Views
    0