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 remove an item from your bot’s outfit? You found it!

https://youtu.be/Am7v5YtAkAA

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

Today we are gonna make a function to remove an item from your bot’s outfit 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 (remove), and the item category.

<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 remove.py inside of our functions folder:

Example of workspace strucure.

Example of workspace strucure.

Here’s what we will need to import into our remove.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 and I will create a list of valid categories:

from highrise import *
from highrise.models import *

categories = ["aura","bag","blush","body","dress","earrings","emote","eye","eyebrow","fishing_rod","freckle","fullsuit","glasses",
"gloves","hair_back","hair_front","handbag","hat","jacket","lashes","mole","mouth","necklace","nose","rod","shirt","shoes",
"shorts","skirt","sock","tattoo","watch"]

async def remove(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 *

categories = ["aura","bag","blush","body","dress","earrings","emote","eye","eyebrow","fishing_rod","freckle","fullsuit","glasses",
"gloves","hair_back","hair_front","handbag","hat","jacket","lashes","mole","mouth","necklace","nose","rod","shirt","shoes",
"shorts","skirt","sock","tattoo","watch"]

async def remove(self: BaseBot, user: User, message: str):
        parts = message.split(" ")
        if len(parts) != 2:
            await self.highrise.chat("Invalid command format. You need to specify the category.")
            return
        if parts[1] not in categories:
            await self.highrise.chat("Invalid category.")
            return
        category = parts[1].lower()
        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][0:3]
            if item_category == category[0:3]:
                try:
                    outfit.remove(outfit_item)
                except:
                    await self.highrise.chat(f"The bot isn't using any item from the category '{category}'.")
                    return
        response = await self.highrise.set_outfit(outfit)
        print(response)

Now let’s understand how the code works:

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