Emoji selfbot - example
Now we make SelfBot for replacing our messages with emojies, because not all clients support custom emojies.
SelfBot is a bot which connect to your main account and get commands only from you.
bot.py structure
from mxbt import Bot, Context, Creds, Listener
from mxbt.types import File
import asyncio
import json
import os
config = json.load(
open('config.json', 'r') # Load config file with bot settings
)
bot = Bot(
prefix=config['prefix'], # Get prefix from config file
creds=Creds.from_json_file(
'credits.json' # Use your main account credits
),
selfbot = True # With that option bot received commands only from self
)
lr = Listener(bot)
# Find dir with emojies in config
path = config['emojies_dir']
files = os.listdir(path)
emojies = dict()
# Iterate for all files in that dir
for file in files:
name = file.split('.')[0]
# Add names and paths of emojeis to dict
emojies[name] = path + file
# Make command aliases from emoji names
@lr.on_command(aliases=emojies.keys())
async def on_emoji_command(ctx: Context) -> None:
# Remove prefix from command
without_prefix = ctx.command.replace(config['prefix'], '')
# Replace context message with emoji
await ctx.edit(
File(emojies[without_prefix]) # For sending files with context - use File class instead
)
# Command for displaying list of all emojies
@lr.on_command(aliases=['list'])
async def on_list_command(ctx: Context) -> None:
text = "\n- ".join(emojies.keys())
await ctx.edit(
f"Powered by: https://codeberg.org/librehub/mxbt\n- {text}",
)
if __name__ == "__main__":
asyncio.run(lr.start_polling()) # Run bot event loop
config.json structure