Recipes

Custom Logger

Seyfert provides a built-in Logger class that can be customized to fit your needs.

Logger.customize()

Override the default log format:

import {  } from 'seyfert';

.(() => {
    const  = new ().();
    const  = (.(). / 1024 / 1024).(1);
    return [`[${}]`, `[${}MB]`, `${}`];
});

File-Based Logging

Enable writing logs to files:

import { Logger } from 'seyfert';

// Log everything to files
Logger.saveOnFile = 'all';

// Or only log errors to files
Logger.saveOnFile = 'error';

// Set the directory for log files
Logger.dirname = 'logs';

Custom Logger Methods

Extend the Logger prototype to add custom methods:

import { Logger, LogLevels } from 'seyfert';

Logger.prototype.success = function (...args: unknown[]) {
    this.rawLog(LogLevels.Info, ...args);
};

Logger.prototype.cmd = function (...args: unknown[]) {
    this.rawLog(LogLevels.Info, ...args);
};

declare module 'seyfert' {
    interface Logger {
        success(...args: unknown[]): void;
        cmd(...args: unknown[]): void;
    }
}

Now you can use them throughout your bot:

import { createEvent } from 'seyfert';

export default createEvent({
    data: { name: 'botReady', once: true },
    run(user, client) {
        client.logger.success(`${user.username} is online!`);
    },
});

Webhook Error Reporting

A common pattern is to report errors to a Discord webhook for monitoring:

import { Embed, type Client } from 'seyfert';

const WEBHOOK_ID = 'your-webhook-id';
const WEBHOOK_TOKEN = 'your-webhook-token';

async function reportError(client: Client, error: Error, context?: string) {
    const embed = new Embed()
        .setTitle('Error Report')
        .setDescription(`\`\`\`\n${error.stack ?? error.message}\n\`\`\``)
        .setColor(0xFF0000)
        .setTimestamp();

    if (context) {
        embed.addFields({ name: 'Context', value: context });
    }

    await client.webhooks.writeMessage(WEBHOOK_ID, WEBHOOK_TOKEN, {
        body: { embeds: [embed] },
    });
}

Use it in your error handlers:


export default class  extends  {
    async (: , : unknown) {
        await .({ : 'Something went wrong!' });

        if ( instanceof ) {
            await (., , `Command: /${.}`);
        }
    }
}