Get Started - Learn How To Make Your Bot!

Guides

Code Snippets

Get methods

Post methods

Web API

Useful links

List of all currently Free Items

List of Emotes

Highrise Bot SDK Changelog


Concept

Want a easier way to change your bot’s outfit color? You found it!

https://youtu.be/5wthq4aeZiw

The code that we’re going to use today is very similar to the code at ‣.

Today we are gonna make a function to change thebot’s outfit color using on_chat commands. To do that we will use the 📬 Command Handler, note that this use is optional, you can implement this function directly on your main code or directly on your on_chat method.

The command works by saying the command (color), the item category, and the color number in the Highrise palette:

<aside> ⚠️ MAKE SURE TO READ HOW CHANGING THE OUTFIT WORKS ABOVE:

</aside>

Highrise Official Documentation for Creators.

Highrise Official Documentation for Creators.

Methods/Functions used:

Required Libraries

Code

First of all, let’s create a new file called color.py inside of our functions folder:

File structure in the workspace.

File structure in the workspace.

Here’s what we will need to import into our color.py file:

from highrise import *
from highrise.models import *

Let’s proceed to our function definition, since we’re using the command handler for this example, your function name will be the command that you will use in the chat to call it, I will name mine as color:

from highrise import *
from highrise.models import *

async def color(self: BaseBot, user: User, message: str):

Finally, let’s implement the function and after it you will see a detailed step by step guide on how the code works:

from highrise import *
from highrise.models import *

async def color(self: BaseBot, user: User, message: str):
        parts = message.split(" ")
        print (parts)
        if len(parts) != 3:
            await self.highrise.chat("Invalid command format. You need to specify the category and color palette number.")
            return
        category = parts[1]
        try:
            color_palette = int(parts[2])
        except:
            await self.highrise.chat("Invalid command format. You need to specify the category and color palette number.")
            return
        outfit = (await self.highrise.get_my_outfit()).outfit
        for outfit_item in outfit:
            #the category of the item in an outfit can be found by the first string in the id before the "-" character
            item_category = outfit_item.id.split("-")[0]
            if item_category == category:
                try:
                    outfit_item.active_palette = color_palette
                except:
                    await self.highrise.chat(f"The bot isn't using any item from the category '{category}'.")
                    return
        await self.highrise.set_outfit(outfit)

Now let’s understand how the code works:

  1. from highrise import * and from highrise.models import *:
  2. async def color(self: BaseBot, user: User, message: str):
  3. parts = message.split(" "):
  4. print(parts):
  5. if len(parts) != 3::
  6. category = parts[1] and color_palette = int(parts[2]):
  7. (await self.highrise.get_my_outfit()).outfit:
  8. The code then iterates through the outfit items to find the items of the specified category.
  9. item_category = outfit_item.id.split("-")[0]:
  10. if item_category == category::
  11. try: outfit_item.active_palette = color_palette:
  12. except: await self.highrise.chat(f"The bot isn't using any item from the category '{category}'."):
  13. await self.highrise.set_outfit(outfit):