简体   繁体   English

小discord.js头像

[英]Small discord.js Avatar image

Avatar issue example头像问题示例

在此处输入图片说明

I am trying to do the discord.js avatar command and it works.我正在尝试执行 discord.js avatar 命令并且它有效。 It sends the image it needs to send but the issue is that the image sent is small compared to other bots.它发送它需要发送的图像,但问题是与其他机器人相比,发送的图像很小。 Am using the command handler in the discord.js guide正在使用 discord.js 指南中的命令处理程序

const Discord = require('discord.js');
module.exports = {
    name: 'avatar',
    description: 'Get the avatar URL of the tagged user(s), or your own avatar.',
    aliases: ['av', 'a'],
    usage: '[commandname]',
    cooldown: 10,
    execute(message) {
        if (!message.mentions.users.size) {
            const embed = new Discord.MessageEmbed()
                .setTitle(message.author.username)
                .setColor(0x00ffff)
                .setImage(message.author.displayAvatarURL({ format: 'png' }));
            return message.channel.send(embed);
        }

        const mention = message.mentions.members.first();
        const Embed = new Discord.MessageEmbed()
            .setTitle(message.mentions.users.first().username)
            .setColor(0x00ffff)
            .setImage(mention.user.displayAvatarURL({ format: 'png' }));
        return message.channel.send(Embed);

    },
};

You can add a size option like how you did with you format您可以添加一个大小选项,就像您如何处理格式一样

.displayAvatarURL({ format: 'png', size: size_you_want }));

the size as to be one of the following 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, For more info you can view the options here https://discord.js.org/#/docs/main/stable/typedef/ImageURLOptions大小为以下 16、32、64、128、256、512、1024、2048、4096 之一,有关更多信息,您可以在此处查看选项https://discord.js.org/#/docs/主/稳定/typedef/ImageURLOptions

There are a few different solutions to this, but the one that I use and prefer is:对此有几种不同的解决方案,但我使用并更喜欢的是:

message.author.displayAvatarURL() + "?size=2048"

You can do whatever you want with this ^ if you want a full avatar command, its:如果你想要一个完整的头像命令,你可以用这个 ^ 做任何你想做的事情,它的:

let embed = new Discord.MessageEmbed();
  if (!message.mentions.users.first()) {
    embed.setColor("00ff00");
    embed.setFooter("Your avatar!");
    embed.setImage(message.author.displayAvatarURL() + "?size=2048");
    message.channel.send(embed);
  } else {
    let user = message.mentions.users.first();
    embed.setFooter(`${user.tag}'s avatar!`);
    embed.setImage(message.mentions.users.first().displayAvatarURL() + "?size=2048");
    embed.setColor("#00ff00");
    message.channel.send(embed);
  }

( Discord.js v12 ) ( Discord.js v12 )

.setImage( user.displayAvatarURL({dynamic: true ,  size: 4096}))

While dynamic:true makes your avatar support all formats.dynamic:true使您的头像支持所有格式。 If users avatar is a gif it will be a gif, if png it will be a png etc.如果用户头像是 gif,它将是 gif,如果是 png,它将是 png 等。

Without it users that have nitro animated avatar will have their avatar frozen on command.没有它,拥有硝基动画化身的用户将根据命令冻结他们的化身。

Change the code from this:从这里更改代码:

const embed = new Discord.MessageEmbed()
                .setTitle(message.author.username)
                .setColor(0x00ffff)
                .setImage(message.author.displayAvatarURL({ format: 'png' }));
            return message.channel.send(embed);```

To this:对此:

const embed = new Discord.MessageEmbed()
                .setTitle(message.author.username)
                .setColor(0x00ffff)
                .setImage(message.author.displayAvatarURL({ dynamic: true }));
            return message.channel.send(embed);```

You only need to add dynamic filter in the image and also remove format filter so it will work with gif image or the image will be static even the user has gif in pic.您只需要在图像中添加动态过滤器并删除格式过滤器,这样它就可以与 gif 图像一起使用,或者即使用户在 pic 中有 gif 图像也将是静态的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM