Search code examples
discord.jsnode-canvas

Getting a users about me if has one using discordjs


So im trying to get the about me section on a users profile and then putting it on a node canvas didn't find a document on the discordjs so just checking if its even possible

my code for the profile canvas:

        const Discord = require('discord.js')
        const Canvas = require('canvas');
        const client = new Discord.Client({
            intents: ['DIRECT_MESSAGES', 'GUILD_MESSAGES', 'GUILDS', 'GUILD_MEMBERS', 'GUILD_MESSAGE_REACTIONS', 'GUILD_VOICE_STATES', 'GUILD_PRESENCES']
        });
        
        const applyText = (canvas, text) => {
        const context = canvas.getContext('2d');
        let fontSize = 70;
    
        do {
            context.font = `${fontSize -= 10}px sans-serif`;
        } while (context.measureText(text).width > canvas.width - 300);
        return context.font;
    };

        client.on('messageCreate', async message => {
            if (message.author.bot) return;
            if (message.channel.type === 'dm') return;
            if (!prefix[message.guild.id]) return;
            if (!langs[message.author.id]) return;
            if (message.content.toLowerCase().startsWith(prefix[message.guild.id].custprefix + 'profile')) {
                const canvas = Canvas.createCanvas(700, 250);
                const context = canvas.getContext('2d');
                const background = await Canvas.loadImage('./profiles/backround.jpg');
                context.drawImage(background, 0, 0, canvas.width, canvas.height);
                context.strokeStyle = '#34eb6e';
                context.strokeRect(0, 0, canvas.width, canvas.height);
        
                context.font = applyText(canvas, message.author.username);
                context.fillStyle = '#ffffff';
        
                context.fillText(message.author.username, canvas.width / 2.5, canvas.height / 3.8);
                context.beginPath();
                context.arc(125, 125, 100, 0, Math.PI * 2, true);
                context.closePath();
                context.clip();
                const avatar = await Canvas.loadImage(message.author.displayAvatarURL({ dynamic: true, format: jpg }));
                context.drawImage(avatar, 25, 25, 200, 200);
                const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'profile-image.png');
                message.channel.send({ files: [attachment] })
            }
        })

Solution

  • Getting a User's bio is currently unavailable to bots.

    An Issue/Feature Request was opened on the discord-api-docs repository

    Description:

    Currently, user bio and banner fields are only returned on the profile endpoint, so they cannot be accessed via bots or OAuth2. It would be useful if they were returned in endpoints that can be accessed.

    You can follow the link for more information