Nubis / Events
Bauen
Events
Typed gateway events, and the intents Nubis works out from them.
Die Nubis-Dokumentation ist auf Englisch, wie die API des Frameworks und seine Meldungen.
Event handlers live in events/. A file default-exports event(...), or an array of them.
// events/welcome.ts
import { event } from "nubis";
export default event("guildMemberAdd", async (member, { api }) => {
// member is Discord's GUILD_MEMBER_ADD payload, typed.
await api.channels.createMessage(WELCOME_CHANNEL, {
content: `Welcome, <@${member.user.id}>!`,
});
});Names
Event names are Discord's in camelCase: MESSAGE_CREATE is messageCreate, GUILD_MEMBER_ADD is guildMemberAdd. The payload is typed from the name, so a typo is a type error. Several files can listen to the same event.
The second argument has api, the event name and the shardId that received it.
Intents
Discord only sends the events a bot asks for, in groups called intents. Nubis reads which events your handlers listen to and asks for the intents they need, so a new messageReactionAdd handler just works.
Some data needs an intent no event implies, such as message content. Add those in the configuration:
export default defineConfig({
intents: ["MessageContent"],
});Message content, server members and presences are privileged: turn them on for your bot in the Developer Portal as well, under Bot › Privileged Gateway Intents.
HTTP bots get no events
Events come over the gateway. A bot on the HTTP transport receives interactions only, and its events/ folder is not used.