Skip to content

Guide: Creating a Custom Command for PieMC

andiricum2 edited this page Aug 1, 2023 · 1 revision

Guide: Creating a Custom Command for PieMC

In this guide, we will walk you through the steps to create a custom command in PieMC using the provided template. We assume you have basic knowledge of Python programming and have already set up PieMC.

Step 1: Create a .py File

  1. Inside your PieMC folder, navigate to the piemc directory.

  2. Inside the piemc folder, go to commands folder.

  3. Within the commands folder, create a new Python file with a meaningful name for your command group, and ensure it has the .py extension.

Step 2: Use the Template

  1. Open the Python file you created in Step 1 using your preferred code editor.

  2. Copy and paste the following template into the Python file:

@Command
def YOURCOMMAND(self):
    self.logger.info("This is an example command.")
  1. Replace YOURCOMMAND with the name of the command you wish to create. Choose a descriptive and relevant name for your command.

  2. Customize the command implementation within the function. You can add any functionality or logic you require for your command. The provided template just logs an example message using the logger.

Step 3: Implement the Command Logic

Now, it's time to implement the actual functionality of your command. You can interact with other components of your plugin, access databases, process data, or anything else you need.

Here's an example of how you can enhance the command functionality:

@Command
def YOURCOMMAND(self):
    # Your command logic here
    name = input("Enter your name: ")
    self.logger.info(f"Hello, {name}! This is your custom command.")

In this example, the command will prompt the user to enter their name, and it will then greet them with a personalized message.

Step 4: Test the Command

Once you have implemented the command logic, it's time to test it. To do this, you'll need to run PieMC.

If your command is executed successfully, you should see the output or logs generated by the logger.info statement in your command implementation.

Congratulations! You have created a custom command for PieMC. You can continue to expand your plugin by adding more commands as needed.

Releases: V0.1 Released Coming Soon

Clone this wiki locally