【问题标题】:Getting a users about me if has one using discordjs如果有使用 discordjs 的用户,请获取有关我的用户
【发布时间】:2021-11-19 04:05:51
【问题描述】:

所以我试图在用户个人资料上获取关于我的部分,然后将其放在节点画布上,但没有在 discordjs 上找到文档,所以只是检查它是否可能

我的个人资料画布代码:

        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] })
            }
        })

【问题讨论】:

  • 不幸的是,目前不可能。官方 Discord 和 Discord.js 文档中没有相关文档。希望 Discord 尽快将其添加到 API 中。

标签: discord.js node-canvas


【解决方案1】:

机器人目前无法获取用户的简历。

An Issue/Feature Request 在 discord-api-docs 存储库中打开

说明:

目前,用户简介和横幅字段仅在配置文件端点上返回,因此无法通过机器人或 OAuth2 访问它们。如果它们在可以访问的端点中返回,那将很有用。

您可以点击链接了解更多信息

【讨论】:

    猜你喜欢
    • 2021-03-13
    • 1970-01-01
    • 2021-07-07
    • 2020-12-09
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多