Skip to content

PrismarineJS/mineflayer-cmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mineflayer-cmd

A simple command manager and handler for Mineflayer plugins.


Getting Started

This plugin is built using Node and can be installed using:

npm install --save mineflayer-cmd

Simple Bot

Loading the plugin can be done the same as any other plugin. Commands can also be loaded at any time.

// Create your bot
const mineflayer = require("mineflayer");
const bot = mineflayer.createBot({ username: "Player" });

// Load the cmd plugin
const cmd = require('mineflayer-cmd').plugin

cmd.allowConsoleInput = true // Optional config argument
bot.loadPlugin(cmd)

// Register your custom command handlers, if desired (plugins can load them too)
function sayCommand(sender, flags, args): Promise<void> {
  return new Promise((resolve, reject) => {
    let message = ''

    if (flags.showsender) message += sender + ": "
    if (flags.color) message += '&' + flags.color[0]

    message += args.join(' ')
    bot.chat(message)
    resolve()
  })  
}

bot.once('cmd_ready', () => {
  bot.cmd.registerCommand('say', sayCommand, // Create a new command called 'say' and set the executor function
            'make me say something', // help text
            'say <message>') // usage text

         // Add a flag called 'color' that expects 1 input
         .addFlag('color', 1, ['color code'], 'Changes the chat color')

         // Add a flag called 'showsender' that expects 0 inputs
         .addFlag('showsender', 0, [], 'If present, displays the sender who sent this message')
})

// And listen for command inputs from any source
// Let's listen for chat events that start with "!"
bot.on('chat', (username, message) => {
  if (message.startsWith('!')) {
    const command = message.substring(1)
    bot.cmd.run(username, command) // Run with the sender and the command itself
  }
})

Documentation

API

Examples

License

This project uses the MIT license.

Contributions

This project is accepting PRs and Issues. See something you think can be improved? Go for it! Any and all help is highly appreciated!

For larger changes, it is recommended to discuss these changes in the issues tab before writing any code. It's also preferred to make many smaller PRs than one large one, where applicable.

About

A command handler plugin for Mineflayer.

Resources

License

Stars

Watchers

Forks

Packages

No packages published