Core Library of commandhandler, a command library that supports the same commands on many platforms with the same code.
Core Library of commandhandler, a command library that supports the same commands on many platforms with the same code.
``bash`
npm i @commandhanlder/core @logmanager/service-{your-choice}
`typescript
import { CommandHandler, StandardArgument, Command } from "@commandhandler/core"
import { YourServiceImplementation } from "@commandhandler/service-{your-service}"
const commandHander = new CommandHandler();
await commandHandler.addService(new YourServiceImplementation())
class PingCommand extends Command
readonly name = "ping"
readonly description = "Ping command"
async onExec(context: CommandExecutionContext, event: CommandExecEvent
await event.actions.reply("pong!")
}
}
await commandHandler.addCommand(new PingCommand())
`
`typescript
import { CommandHandler, StandardArgument, Command, RequireArgumentCommandError } from "@commandhandler/core"
import { DiscordImplementation } from "@commandhandler/service-discord.js"
import { ErrorCollection } from "@commandhandler/i18n-de"
import { LogManager, LogLevel } from "@logmanager/core"
import { ConsoleLogger } from "@logmanager/package-console"
const logManager = new LogManager(new ConsoleLogger(), LogLevel.VERBOSE)
const germanErrorCollection = new ErrorCollection()
germanErrorCollection.register(
RequireArgumentCommandError.id,
(error: RequireArgumentCommandError) =>
Argument '${error.argument.name}' ist erforderlich für das Kommando '${error.command.name}'.,
"DE",
)
const commandHander = new CommandHandler(logManager, germanErrorCollection);
await commandHandler.addService(new DiscordImplementation.createClient(process.env.DISCORD_TOKEN))
class PingCommand extends Command
readonly name = "ping"
readonly description = "Ping command"
async onExec(context: CommandExecutionContext, event: CommandExecEvent
await event.actions.reply("pong!")
}
}
await commandHandler.addCommand(new PingCommand())
``