Najova

DocsExtensionsdiscord.najova

discord.najova/canvas0.0.2

Official Najova Package

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

canvas: picture cards

Needs discord.najova 0.0.7 or newer.

Switch it on for your project on the Packages page in Najova IDE (Home > Packages), where the card colours are set. Then $use[discord] alone gives:

$use[discord]
$event[join]
  $let[c;$context]
  $reply[$get[c.event];$table[content;Welcome!;files;$list[$welcomeCard]]]
$endevent
$start[$env[DISCORD_TOKEN]]
FunctionGives
$welcomeCard or $welcomeCard[person;options]a welcome card (a PNG file)
$rankCard[stats] or $rankCard[stats;person;options]a rank card; $xpStats gives the stats

options: colour, background, title and text.

The older way ($call)

Bots made before 0.0.7 keep working:

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

$use[discord]
$use[discord/canvas]
$on[discord.Join;member]
  $let[card;$call[canvas.welcome;$get[member];nil;$table[colour;#f3c13a]]]
  $call[discord.send;$get[member];$table[content;Welcome!;files;$list[$get[card]]]]
$endon
$call[discord.start;$env[DISCORD_TOKEN]]

With the xp package, a rank card:

$let[card;$call[canvas.rank;$get[cmd];nil;$call[xp.stats;$get[cmd]]]]
$call[discord.reply;$get[cmd];$table[files;$list[$get[card]]]]

Calls

CallWhat it does
$call[canvas.welcome;where;person;options]A 1024×400 welcome card: avatar, "WELCOME", name, "Member #N of Server"
$call[canvas.rank;where;person;stats;options]A 934×282 rank card: avatar, name, level and an XP bar. stats is a table with level, into and need (xp.stats gives one)
  • person: an id, or nil for the person of the event.
  • options (all may be left out): colour (#5865f2), background (#1e1f22), title (welcome card), text (the small line).
  • Each call gives the path of a PNG file in the bot's folder (discord-cards/, the newest 50 are kept). Send it with a message's files list.
  • When the avatar cannot be loaded, the card shows the first letter of the name.

The pictures are drawn with @napi-rs/canvas (MIT); the fonts are Montserrat and Baloo 2 (SIL Open Font License 1.1, fonts/OFL-*.txt). This package has a Node part (helper-part.mjs): run npm install in this folder once (the installer does this for you).

Needs discord.najova 0.0.2 or newer.

Functions

canvas.welcome

$call[canvas.welcome;where;person;options]

A welcome card for a person (nil: the person of the event), as a PNG file in discord-cards/. options: colour, background, title and text.

canvas.rank

$call[canvas.rank;where;person;stats;options]

A rank card: stats is a table with level, into and need ($call[xp.stats] gives one). options as for welcome.

canvas.welcomeCard

$welcomeCard or $welcomeCard[person;options]

A welcome card (a PNG file) for the person of the event, or the member whose id is given. options: colour, background, title, text.

canvas.rankCard

$rankCard[stats] or $rankCard[stats;person;options]

A rank card (a PNG file); stats is a table with level, into and need ($xpStats gives one).