Skip to content

Custom emotes

In some clients (FluffyChat, Cinny, etc...) you can setup your own emotes packs for account and for a rooms.

mxbt can load this packs and send emojis with simple emoji codes. This is what you need:

  • Add emotes pack to bot account (via any supported client)
  • Know emoji shortcodes
  • Include emoji shortcode with this syntax - :shortcode: in message text
  • Specify emotes list with names of used emotes without any additionals

Warning

This is works only with use_html=True parameter!

bot.py structure

from mxbt import Bot, Context, Creds, Filter, Listener
import asyncio

bot = Bot(
    prefix="!",                 # Standart command prefix, commands can setup it own prefix
    creds=Creds.from_json_file(
        "credits.json"          # You can also make Credits object via providing Dict with same structure 
    )
)
lr = Listener(bot)

@lr.on_command(aliases=["echo", "e"])       # Usage of prefix is optional
@Filter.from_users(['@username:matrix.org']) # Event received only from this senders
async def ctx_echo(ctx: Context) -> None:    # Context object contains main info about event
    await ctx.reply(
        "Hey :emote_code:!", 
        use_html=True,
        emotes=['emote_code']
    ) # Reply message to event room with specified emotes

if __name__ == "__main__":
    asyncio.run(lr.start_polling()) # Run bot event loop

You also can get emotes just using:

  • Bot.user_emotes: dict
  • Bot.room_emotes: dict
  • Bot.get_user_emote(name: str) -> str | None - Return emote file url (mxc)
  • Bot.get_room_emote(room_id: str, pack: str, name: str) -> str | None - Return emote file url (mxc)