# Building a Chat Bot with the highrise Library: A Step-by-Step Explanation

**URL:** <https://createforum.highrise.game/t/building-a-chat-bot-with-the-highrise-library-a-step-by-step-explanation/714>\
**Category:** Bots API\
**Tags:** bots, webapi, studio\
**Created:** [January 23, 2024, 7:27pm UTC](https://createforum.highrise.game/t/building-a-chat-bot-with-the-highrise-library-a-step-by-step-explanation/714 "2024-01-23T19:27:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![A001001](https://yyz2.discourse-cdn.com/flex036/user_avatar/createforum.highrise.game/a001001/32/479_2.png) [@A001001](https://createforum.highrise.game/u/A001001)\
**Post date:** [January 23, 2024, 7:27pm UTC](https://createforum.highrise.game/t/building-a-chat-bot-with-the-highrise-library-a-step-by-step-explanation/714/1 "2024-01-23T19:27:07Z")

</div>

![highrise logo](https://canada1.discourse-cdn.com/flex036/uploads/highrise1/original/1X/51311ced72a925bbc4399f0bd2146da7f6a47694.png)

[GitHub LINK OF ECHO BOT HIGHRISE](https://github.com/pocketzworld/example-bots/blob/main/echo/echo_bot.py)

**ECHO BOT CODE EXPLANATION FOR NEW USERS:**

> from highrise import BaseBot, CurrencyItem, Item, Position, Reaction, SessionMetadata, User

This line imports various classes from the `highrise` library that are likely used within the bot.

> class Bot(BaseBot):

A new class `Bot` is defined, which inherits from `BaseBot` . This implies that `Bot` is a specialized version of the `BaseBot` class from the `highrise` library.

> async def on\_user\_join(self, user: User) → None:  
> “”“On a user joining the room.”“”  
> print(f"[JOIN] {user.username}")

This is a method called `on_user_join` that is triggered when a user joins the room. It prints a message indicating the event along with the username of the user who joined.

> async def on\_user\_leave(self, user: User) → None:  
> “”“On a user leaving the room.”“”  
> print(f"[LEAVE] {user.username}")

This method is called when a user leaves the room. It takes a `User` object as a parameter, representing the user who left. The method prints a message indicating the event, including the username of the user who left the room.

> async def on\_channel(self, sender\_id: str, message: str, tags: set[str]) → None:  
> “”“On a hidden channel message.”“”  
> pass # This method does nothing (pass) when a hidden channel message is received.

This method is triggered when a message is sent on a hidden channel. It takes the `sender_id` (ID of the sender), the message content, and a set of tags as parameters. However, in this implementation, it does nothing (`pass` ). You might extend this method to handle hidden channel messages based on your specific requirements.

> async def on\_start(self, session\_metadata: SessionMetadata) → None:  
> print(“[START]”)

This method is called when the bot starts. It takes `session_metadata` as a parameter, which could contain information about the session. The method simply prints a message indicating the start of the bot.

> async def on\_chat(self, user: User, message: str) → None:  
> print(f"[CHAT] {user.username}: {message}")

This method is triggered when a chat message is received. It takes a `User` object and the message content as parameters. The method prints a message indicating the chat event, including the username of the user who sent the message and the message content.

> async def on\_whisper(self, user: User, message: str) → None:  
> “”“On a whisper.”“”  
> print(f"[WHISPER] {user.username} {message}")

This method is called when a whisper (a private message) is received. It takes a User object and the message content as parameters. The method prints a message indicating the whisper event, including the username of the user who sent the whisper and the whisper content.

> async def on\_emote(self, user: User, emote\_id: str, receiver: User | None) → None:  
> “”“On a received emote.”“”  
> print(f"[EMOTE] {user.username} {emote\_id} {receiver}")

This method is triggered when an emote is received. It takes the sender (`User`), emote ID, and optionally a receiver (`User` or `None`) as parameters. The method prints a message indicating the emote event, including the username of the user who sent the emote, the emote ID, and the receiver’s username if applicable.

> async def on\_reaction(self, user: User, reaction: Reaction, receiver: User) → None:  
> “”“Called when someone reacts in the room.”“”  
> print(f"[REACTION] {user.username} {reaction} {receiver.username}")

This method is called when someone reacts in the room. It takes the user who reacted (`User` ), the reaction object, and the receiver (`User` ) as parameters. The method prints a message indicating the reaction event, including the usernames of the user who reacted, the reaction itself, and the username of the receiver.

> async def on\_tip(  
> self, sender: User, receiver: User, tip: CurrencyItem | Item  
> ) → None:  
> “”“On a tip received in the room.”“”  
> print(f"[TIP] {sender.username} {receiver.username} {tip.type} {tip.amount}")

This method is triggered when a tip is received in the room. It takes the sender (`User`), receiver (`User`), and the tip (either `CurrencyItem` or `Item`) as parameters. The method prints a message indicating the tip event, including the usernames of the sender and receiver, the type of tip, and the tip amount.

> async def on\_user\_move(self, user: User, pos: Position) → None:  
> “”“On a user moving in the room.”“”  
> print(f"[MOVE] {user.username} {pos.x} {pos.y} {pos.z}")

This method is called when a user moves in the room. It takes the user (`User` ) and the position (`Position` object) as parameters. The method prints a message indicating the move event, including the username of the user who moved and the coordinates (x, y, z) of their new position.

---

<div class="post-metadata">

**Author:** ![Mr\_whitee](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@Mr\_whitee](https://createforum.highrise.game/u/Mr_whitee)\
**Post date:** [July 3, 2024, 3:49pm UTC](https://createforum.highrise.game/t/building-a-chat-bot-with-the-highrise-library-a-step-by-step-explanation/714/2 "2024-07-03T15:49:51Z")

</div>

could anyone prephaps send me a bot script with working capabilities able to chnage floors and all that i would really appricate it
