Node.js Discord.js欢迎消息不显示头像

Node.js Discord.js欢迎消息不显示头像,node.js,discord,discord.js,Node.js,Discord,Discord.js,我有以下问题。这段代码可以工作,但如果用户没有配置文件图片,则会显示错误,并且不会发送嵌入 守则: client.on('guildMemberRemove', member => { welcome = JSON.parse(fs.readFileSync("./commands/welcome.json", "utf8")) if(!welcome[member.guild.id]) return if(!welcome[member.gu

我有以下问题。这段代码可以工作,但如果用户没有配置文件图片,则会显示错误,并且不会发送嵌入

守则:

   client.on('guildMemberRemove', member => {   
     welcome = JSON.parse(fs.readFileSync("./commands/welcome.json", "utf8"))
     if(!welcome[member.guild.id]) return
       if(!welcome[member.guild.id].channel) return

        const welcome1 = new Discord.RichEmbed()
        .setTitle(`${member.user.username} left the server`)
        .setDescription("Please come back, it was such a good time with you :(")
        .setColor("RED")
        .setThumbnail(`${member.user.avatarURL}`)

        member.guild.channels.get(welcome[member.guild.id].channel).send(welcome1)

     })
错误:

    (node:16164) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.thumbnail.url: Not a well formed URL.
    at C:\Users\Bendix\Desktop\MemeBot\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
    at C:\Users\Bendix\Desktop\MemeBot\node_modules\snekfetch\src\index.js:215:21
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:16164) 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(). (rejection id: 2)
(node:16164) [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.

有人能帮我吗?

那是因为默认的化身不是存储在.avatarURL下,而是存储在.defaultAvatarURL下。所以你必须这样做:

     welcome = JSON.parse(fs.readFileSync("./commands/welcome.json", "utf8"))
     if(!welcome[member.guild.id]) return
       if(!welcome[member.guild.id].channel) return

        const welcome1 = new Discord.RichEmbed()
        .setTitle(`${member.user.username} left the server`)
        .setDescription("Please come back, it was such a good time with you :(")
        .setColor("RED")
        .setThumbnail(`${member.user.displayAvatarURL()}`)

        member.guild.channels.get(welcome[member.guild.id].channel).send(welcome1)

     })```
let url=member.user.AvatarURL==未定义?member.user.defaultAvatarURL:member.user.avatarURL
const welcome1=新的Discord.RichEmbed()
.setTitle(`${member.user.username}离开了服务器`)
.setDescription(“请回来,和你在一起真是太好了:(”)
.setColor(“红色”)
.set缩略图(url)
member.guild.channels.get(欢迎[member.guild.id].channel).发送(welcome1)

通过这种方式,它使用一行if语句来检查用户是否有自定义化身,如果没有,则用默认化身替换它。

如果我尝试了这种方法,但它会显示默认化身。如果它显示默认化身URL,则意味着用户没有自定义化身集。但是它有自定义化身,所以你说它甚至会显示de如果用户设置了自定义的头像,是否会出错?是的,我现在正在使用代码,它会显示出来。这个用户有一张个人资料图片