Skip to main content
Glama
TemporarySubscriber.ts840 B
import { Bot } from 'mineflayer' class Subscription { constructor (readonly eventName: string, readonly callback: Function) {} } export class TemporarySubscriber { private readonly subscriptions: Subscription[] = [] constructor (readonly bot: Bot) {} /** * Adds a new temporary event listener to the bot. * * @param event - The event to subscribe to. * @param callback - The function to execute. */ subscribeTo (event: string, callback: Function): void { this.subscriptions.push(new Subscription(event, callback)) // @ts-expect-error this.bot.on(event, callback) } /** * Removes all attached event listeners from the bot. */ cleanup (): void { for (const sub of this.subscriptions) { // @ts-expect-error this.bot.removeListener(sub.eventName, sub.callback) } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/leo4life2/minecraft-mcp-http'

If you have feedback or need assistance with the MCP directory API, please join our Discord server