javascript - Small discord.js Avatar image - Stack Overflow

Avatar issue exampleI am trying to do the discord.js avatar mand and it works. It sends the image it ne

Avatar issue example

I am trying to do the discord.js avatar mand and it works. It sends the image it needs to send but the issue is that the image sent is small pared to other bots. Am using the mand handler in the discord.js guide

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: '[mandname]',
    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);

    },
};

Avatar issue example

I am trying to do the discord.js avatar mand and it works. It sends the image it needs to send but the issue is that the image sent is small pared to other bots. Am using the mand handler in the discord.js guide

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: '[mandname]',
    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);

    },
};
Share edited Oct 28, 2020 at 12:37 Manoj 2,0853 gold badges13 silver badges25 bronze badges asked Oct 28, 2020 at 3:49 OmGiTsLaiLOmGiTsLaiL 391 silver badge5 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

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/#/docs/main/stable/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 mand, 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)

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

While dynamic:true makes your avatar support all formats. If users avatar is a gif it will be a gif, if png it will be a png etc.

Without it users that have nitro animated avatar will have their avatar frozen on mand.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745069036a4609432.html

相关推荐

  • javascript - Small discord.js Avatar image - Stack Overflow

    Avatar issue exampleI am trying to do the discord.js avatar mand and it works. It sends the image it ne

    20小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信