简体   繁体   English

拾取用户头像时出错 (discord.js)

[英]Error picking up the user's avatar (discord.js)

Code代码

module.exports.run = async (bot, message, args) =>{

// at the top of your file
const discord = require('discord.js');
const config = require("../config");

// inside a command, event listener, etc.
const embed = new discord.MessageEmbed()
    .setColor('RANDOM')
    .setTitle('Créditos do Os Profissionais')
    .setURL('https://discord.gg/')
    .setAuthor('Effy', 'https://i.imgur.com/wSTFkRM.png', 'https://stackoverflow.com/users/15303029/meredithgrey')
    .setDescription('Criador do grupo e desenvolvedor do BOT')
    .setThumbnail('https://i.imgur.com/1oHJJZQ.png')
    .addFields(
        { name: 'Créditos de equipe', value: 'Equipe gestora' },
        { name: '\u200B', value: '\u200B' },
        { name: 'Snoot', value: 'Owner', inline: true },
        { name: 'Texugo', value: 'Owner', inline: true },
    )
    .addField('Leo', 'Owner', true)
    .setImage('https://i.imgur.com/1oHJJZQ.png')
    .setTimestamp()
    .setFooter(message.author.username, message.author.avatar);

    message.channel.send(embed);
}
module.exports.config = {
    name: "credits",
    aliases: ["creditos"]
}

Error:错误:

(node:5676) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.footer.icon_url: Scheme "fbea7946b1cf05e3bfbff344733ba775" is not supported. Scheme must be one of ('http', 'https').
    at RequestHandler.execute (C:\Users\Pc\Desktop\RemakeTO\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RequestHandler.push (C:\Users\Pc\Desktop\RemakeTO\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5676) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5676) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Since when I started using discord.js V12 i walk with many doubts and one of them is, how to catch the avatar of a user?自从我开始使用 discord.js V12 以来,我一直有很多疑问,其中之一是,如何捕捉用户的头像? Can someone help me?有人能帮我吗? I know it's a stupid doubt but I really don't know我知道这是一个愚蠢的怀疑,但我真的不知道

message.author.avatar is not a method. message.author.avatar不是一种方法。 You need message.author.avatarURL你需要message.author.avatarURL

//author's avatar:
.setThumbnail(message.author.avatarURL);

As mentioned above, try using the docs如上所述,尝试使用文档

// In discord.js v12 message.author.displayAvatarURL()

I was having a similar issue.我遇到了类似的问题。 The problem was that Discord was being sent the embed before the promise of fetching the user and image was fulfilled.问题是在实现获取用户和图像的承诺之前,Discord 被发送到嵌入。 This is the code I used to get this functionality.这是我用来获得此功能的代码。

const client = new Discord.Client();
let thanos = client.users.fetch('IDHERE');
thanos.then(function(result1) {
    //put your code that uses the result1 (the user object) here
    //for example, you could put your entire embed in here and
    //in setFooter you could use result1.displayAvatarURL()
});

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

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