Nubis / Replies
Build
Replies
One reply() for every case, what Nubis does when a handler is slow, and files, embeds and mentions.
Discord gives a bot three seconds to answer an interaction, then fifteen minutes of follow-ups through a different endpoint, with different rules for editing, deferring and visibility. Most bots track all of this by hand. In Nubis you call reply().
What reply() does
| When you call it | What Nubis sends |
|---|---|
| First, within the time limit | The interaction's response |
| First, after Nubis already showed "thinking…" | An edit of that "thinking…" message |
| Second and later | Follow-up messages |
Calls are queued, so two reply()s without await still arrive in order.
Slow handlers
If a handler hasn't answered after two seconds, Nubis sends "thinking…" for it, which gives the handler up to fifteen minutes. The reply that follows replaces it. You don't have to call defer(); do it yourself only to start earlier or to choose who sees it:
run: async ({ defer, reply }) => {
await defer({ ephemeral: true });
const report = await buildReport(); // takes a while
await reply(report);
},autoDeferMs in the configuration changes the two seconds, or turns this off with false.
Who sees it
ephemeral: true on a command makes its replies visible only to the user who ran it. A single reply can say otherwise:
await reply({ content: "Only you can see this.", ephemeral: true });When the first reply's visibility differs from the "thinking…" message already sent, Nubis deletes "thinking…" and sends the reply as a follow-up, because Discord can't change a message's visibility by editing it.
Messages
reply() takes a string, or an object:
| Field | What it is |
|---|---|
content | The text. |
embeds | Discord embeds. |
components | Buttons and selects. Bare buttons are packed five to a row; each select gets its own row. |
files | Up to ten attachments. |
ephemeral | See above. |
allowedMentions | Who the message may ping. |
Files
await reply({
content: "Here's the report.",
files: [{ name: "report.csv", data: csv }],
});data can be a string, bytes or a Blob. Give images a description for alt text. An embed can show an attached image with attachment://report.png.
Mentions are safe by default
Nubis only lets a message ping the users it mentions — never @everyone, @here or roles — so echoing what a user typed can't mass-ping a server. Pass allowedMentions to allow more.
Errors
When a handler throws, Nubis tells the user "Something went wrong. Please try again." — as a reply, an edit or a follow-up, whichever still works — and passes the error to onError. See Errors.