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


Added on version 23.1.0b5

change_room_privilege(self, user_id: str, permissions: RoomPermissions ) -> None:

Change the room privilege for given user_id.

⚙️ Use cases

Here’s an example on how to promote an user using a “promote <@user> <role>” command on chat:

async def on_chat(self, user: User, message: str) -> None:
        if message.startswith("promote"):
            if user.username != "ItsVini":
                await self.highrise.chat("You do not have permission to use this command.")
                return
            parts = message.split()
            if len(parts) != 3:
                await self.highrise.chat("Invalid promote command format.")
                return
            command, username, role = parts
            if "@" not in username:
                username = username
            else:
                username = username[1:]
            if role.lower() not in ["moderator", "designer"]:
                await self.highrise.chat("Invalid role, please specify a valid role.")
                return
            #check if user is in room
            room_users = (await self.highrise.get_room_users()).content
            for room_user, pos in room_users:
                if room_user.username.lower() == username.lower():
                    user_id = room_user.id
                    break
            if "user_id" not in locals():
                await self.highrise.chat("User not found, please specify a valid user and coordinate")
                return
            #promote user
            permissions = (await self.highrise.get_room_privilege(user_id))
            setattr(permissions, role.lower(), True)
            try:
                await self.highrise.change_room_privilege(user_id, permissions)
                await self.highrise.chat(f"{username} has been promoted to {role}.")
            except Exception as e:
                await self.highrise.chat(f"Error: {e}")
                return
            
        if message.startswith("demote"):
            if user.username != "ItsVini":
                await self.highrise.chat("You do not have permission to use this command.")
                return
            parts = message.split()
            if len(parts) != 3:
                await self.highrise.chat("Invalid demote command format.")
                return
            command, username, role = parts
            if "@" not in username:
                username = username
            else:
                username = username[1:]
            if role.lower() not in ["moderator", "designer"]:
                await self.highrise.chat("Invalid role, please specify a valid role.")
                return
            #check if user is in room
            room_users = (await self.highrise.get_room_users()).content
            for room_user, pos in room_users:
                if room_user.username.lower() == username.lower():
                    user_id = room_user.id
                    break
            if "user_id" not in locals():
                await self.highrise.chat("User not found, please specify a valid user and coordinate")
                return
            #promote user
            permissions = (await self.highrise.get_room_privilege(user_id))
            setattr(permissions, role.lower(), False)
            try:
                await self.highrise.change_room_privilege(user_id, permissions)
                await self.highrise.chat(f"{username} has been demoted from {role}.")
            except Exception as e:
                await self.highrise.chat(f"Error: {e}")
                return

Here’s an step by step explanation on how this code works:

  1. async def on_chat(self, user: User, message: str) -> None::
  2. if message.startswith("promote"):
  3. if user.username != "ItsVini":
  4. parts = message.split():
  5. if len(parts) != 3:
  6. command, username, role = parts:
  7. if "@" not in username::
  8. else::
  9. if role.lower() not in ["moderator", "designer"]:
  10. (await self.highrise.get_room_users()).content:
  11. for room_user, pos in room_users:
  12. if room_user.username.lower() == username.lower():
  13. if "user_id" not in locals():
  14. (await self.highrise.get_room_privilege(user_id)):
  15. setattr(permissions, role.lower(), True):
  16. await self.highrise.change_room_privilege(user_id, permissions):
  17. except Exception as e::