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

This is a simple code snippet to show how to make a target user perform a given emote using only on_chat commands:

https://youtu.be/QF6CLEdmYOw

Today we are gonna make a function to make a target user perform a given emote 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 format used is /emote <username> <emote_id>.

Methods/Functions used:

Required Libraries

Code

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

Untitled

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

from highrise import *
from highrise.models import *
from highrise.webapi import *
from highrise.models_webapi 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 equip:

from highrise import *
from highrise.webapi import *
from highrise.models_webapi import *
from highrise.models import *

async def emote(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 *
from highrise.webapi import *
from highrise.models_webapi import *

async def emote(self: BaseBot, user: User, message: str) -> None:
    try:
        command, target, emote_id = message.split(" ")
    except:
        await self.highrise.chat("Invalid command format. Please use '/emote <target> <emote_id>.")
        return
    user = (await self.webapi.get_users(username=target))
    if user.total == 0:
        await self.highrise.chat("Invalid target.")
        return
    user_id = user.users[0].user_id
    try:
        await self.highrise.send_emote(emote_id, user_id)
    except:
        await self.highrise.chat("Invalid emote.")
        return

Now let’s understand how the code works:

  1. from highrise import *, from highrise.models import *, from highrise.webapi import *, and from highrise.models_webapi import *:
  2. async def emote(self: BaseBot, user: User, message: str) -> None::
  3. try: command, target, emote_id = message.split(" ") except: await self.highrise.chat("Invalid command format. Please use '/emote <target> <emote_id>'.") return:
  4. user = (await self.webapi.get_users(username=target)):
  5. if user.total == 0::
  6. user_id = user.users[0].user_id:
  7. try: await self.highrise.send_emote(emote_id, user_id) except: await self.highrise.chat("Invalid emote.") return: