How can I make a function work only for desktops and not for mobiles?

WordPress does have a helper function for detecting mobile devices, wp_is_mobile() (untested):

if  ( ! wp_is_mobile() ) {
    echo do_shortcode( '[meta_gallery_slider arrows="false" show_caption="false" show_title="false" autoplay="false" slider_height="450"]' ); 
}

As Jacob Peattie mentioned, this is unreliable. Better option is to use CSS to show the output only for viewport widths above specified value (untested):

PHP:

printf( 
    '<div class="hide-if-mobile">%s</div>', 
    do_shortcode( '[meta_gallery_slider arrows="false" show_caption="false" show_title="false" autoplay="false" slider_height="450"]' ) 
);

CSS:

@media ( max-width: 768px ) {
    .hide-if-mobile { display: none; }
}