【问题标题】:avatarURL and displayAvatarURL doesn't work on my bot discord javascriptavatarURL 和 displayAvatarURL 在我的机器人不和谐 javascript 上不起作用
【发布时间】:2020-07-02 10:41:53
【问题描述】:

我正在为我的 discord 服务器编写一个机器人,我创建了一个命令,当被调用时,它可以工作。

确实,当用户键入“!embed theTextToEmbedHere”时,机器人会删除他的消息并发送一个嵌入,其中包含他的消息。 当我显示作者用户名和所有这些东西时,一切正常,但是当我尝试显示机器人或作者的头像时,什么都没有显示。 我到处搜索,给出的所有功能都不起作用。

这是我的简化代码(没有有效的东西):

module.exports = async(client, message) => {
        //Already done all the test to check if the the command is called
        const membre = message.member;
        var avatar = membre.user.avatarURL; //Or displayAvatarURL

        var embed = new Discord.MessageEmbed()
                    .setColor(0x00a5ff)
                    .setAuthor(`${membre.displayName}`, avatar);
        message.channel.send(embed);
};

//Name the command after

当我尝试显示嵌入时,头像没有出现在嵌入上,这与我想要显示的用户名和所有其他信息相反。 提前致谢。

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    好的,我终于发现:我必须将dynamic的参数设置为true

    message.channel.send(message.author.avatarURL({ dynamic:true }));
    

    【讨论】:

      【解决方案2】:

      在 discord.js v12 中需要在 avatarURL 或 displayAvatarURL 后添加括号

      像这样:

      message.channel.send(message.author.avatarURL());
      

      【讨论】:

        【解决方案3】:

        我是机器人开发人员 看来你在其他地方犯了错误......不是你认为你做的地方 您可以复制并粘贴我的代码以显示 avatarUrl:

        bot.on('message', message => {
        const args = message.content.slice(P.length).trim().split(/ +/)
        //If member wants his own avatar
        switch (args[0]) {
                       //The command:
                       case 'pfp':
                    const user = message.mentions.users.first()
                    //If member wants his own avatar
                    if(!args[1]) {
                        var embed = new Discord.MessageEmbed()
                        .setColor('YELLOW')
                        .setDescription('<@' + message.author.id + '>' + `'` +'s profile picture')
                        .setImage(message.author.avatarURL())
                        .setTimestamp()
                        .setFooter(`${message.author.username}`, message.author.avatarURL({ dynamic: true , size: 2048 , format: "png" }))   
                        message.channel.send(embed)
                    //If member wants other people avatar:
                    }else{
                        var embed = new Discord.MessageEmbed()
                        .setColor('YELLOW')
                        .setDescription('<@' + user.id + '>' + `'` +'s profile picture'+' ')
                        .setImage(user.avatarURL())
                        .setTimestamp()
                        .setFooter(`${message.author.username}`, message.author.avatarURL())
                        message.channel.send(embed)
                    }
                break
        

        } })

        【讨论】:

          【解决方案4】:

          如果您使用的是 Typescript,它会抱怨 message.author.avatarURL() 将返回 string | undefined

          你可以这样做:

          setFooter(..., `${message.author.avatarURL({ dynamic: true , size: 2048 , format: "png" })}`)
          

          【讨论】:

            猜你喜欢
            • 2020-11-18
            • 2018-03-20
            • 2021-09-12
            • 2021-04-30
            • 2020-07-19
            • 1970-01-01
            • 2021-11-18
            • 2022-10-07
            • 2021-10-05
            相关资源
            最近更新 更多