DEV Community

Cover image for Get a user's banner in discord.js v12
Tejas Lamba
Tejas Lamba

Posted on

Get a user's banner in discord.js v12

The code will be below

Discord Server - https://discord.gg/vUYvswzwMH

YouTube - https://www.youtube.com/c/visa2code

So it uses the Cryptons API

If user has a banner it will reply with a banner

Banner

What if user doesnt have a banner?

It will reply with user doesnt have a banner

No Banner

Code
https://srcb.in/C97M8fDOIK

 const { MessageEmbed } = require('discord.js');
const axios = require('axios');
  const user = message.mentions.users.first() || client.users.cache.get(args[0]) || await client.users.fetch(args[0]).catch(err => undefined);
    if (!user) return message.reply('You must mention someone to get there banner').catch(console.error);

    const res = await fetch(`https://cryptons.ga/api/v1/userbanner?id=${user.id}`)

    const json = res.json()

    if(json.url === "null") return message.repy('User doesnt have a banner')

    axios.get(`https://cryptons.ga/api/v1/userbanner?id=${user.id}`)
        .then(function(response) {
        if(response.data.url === "null") return message.reply('User doesnt have a banner')
            const embed = new MessageEmbed()
                .setTitle(`Banner`)
                .setImage(response.data.url)
                .setColor('RANDOM')
            message.channel.send(embed);
        });
Enter fullscreen mode Exit fullscreen mode

Top comments (0)