Package
plugin-mongoose v0.7.0

About
@seedcord/plugin-mongoose connects a seedcord bot to MongoDB through Mongoose. It connects when the bot starts, loads your service classes, and disconnects when the bot shuts down. Handlers can reach each service through this.core.
Install it when your bot stores data in MongoDB. It works with a gateway bot and with an http bot on your own server. On a Cloudflare Workers bot, attaching it is a compile error.
seedcord is pre-1.0, so a minor version can break your bot. Each release's changelog says what changed and how to update.
Installation
pnpm add @seedcord/plugin-mongoose mongooseUsage
Attach the plugin in bot.ts. Read it from this.core in a handler, under the key you pass:
// bot.ts
import { Seedcord } from '@seedcord/gateway';
import { Mongoose } from '@seedcord/plugin-mongoose';
import { GatewayIntentBits } from 'discord.js';
import { Converters, Envapter } from 'envapt';
export default new Seedcord({
bot: {
clientOptions: { intents: [GatewayIntentBits.Guilds] },
interactions: { path: './handlers' },
commands: { path: './commands' },
events: { path: null }
},
subscribers: { path: null }
}).attach('db', Mongoose, {
dir: './services',
uri: Envapter.getRequired('MONGO_URI', Converters.String),
name: 'my-bot'
});Each file in services/ holds a service with its schema:
// services/Users.ts
import { MongooseService, RegisterMongooseService } from '@seedcord/plugin-mongoose';
import mongoose from 'mongoose';
interface IUser {
userId: string;
balance: number;
}
@RegisterMongooseService('users')
export class Users extends MongooseService<IUser> {
public static schema = new mongoose.Schema<IUser>({
userId: { type: String, required: true, unique: true },
balance: { type: Number, default: 0 }
});
public async findByUserId(userId: string) {
return this.model.findOne({ userId });
}
}Run seedcord codegen after you add or rename a service. It adds the service's key to MongooseServices, the type behind the decorator and core.db.services. Then call await this.core.db.services.users.findByUserId(this.user.id) from a handler. The Mongoose guide covers the options, services, and errors.