Skip to content

event()

Popii


Popii / event

event<K>(handler): PopiiEventFunction<K>

Defined in: define/event.ts:52

Wraps a Discord.js event handler with the Popii EventPop context.

Name the file after the Discord.js event you want to handle (e.g. guildMemberAdd.ts) and drop it in src/events/. Popii loads it automatically and infers the required Gateway intents from the filename — no manual intent configuration needed.

The first argument is always EventPop (the Popii context object). The remaining arguments match the Discord.js event signature exactly.

K extends keyof ClientEvents

PopiiEventFunction<K>

The asynchronous function to run when the event fires.

PopiiEventFunction<K>

src/events/guildMemberAdd.ts
import { event } from "popii";
export default event(async (pop, member) => {
const channel = member.guild.systemChannel;
await channel?.send(`Welcome to the server, ${member}! 👋`);
});
src/events/guildCreate.ts
import { event } from "popii";
export default event(async (pop, guild) => {
pop.log.info(`Joined "${guild.name}" (${guild.memberCount} members)`);
});
src/events/messageCreate.ts
import { event } from "popii";
export default event(async (pop, message) => {
if (message.author.bot) return;
if (message.content.toLowerCase() === "hello") {
await message.reply("Hello there!");
}
});