def build_emoji_dict(guild):
    """ Build an emoji dict for given guild, suitable as 'custom'
        argument to parse_emojis.
        Only emojis the bot is allowed to use are kept.
    """
    my_roles = set(guild.me.roles)
    return dict(
        (emoji.name, emoji) for emoji in guild.emojis
        if not emoji.roles or my_roles.intersection(emoji.roles)
    )