【问题标题】:Discord JS problem get username & avatarURL by mentionDiscord JS问题通过提及获取用户名和头像URL
【发布时间】:2021-02-01 02:09:47
【问题描述】:

我尝试在我的服务器 discord 上提及一个成员,并使用他的用户名和 avatarURL 创建一个 webhook,但它不起作用,它告诉我我的用户提到的没有 displayName

我的代码:

 if (cmd === "say")
    {
        message.delete()   
        let usermentioned = message.mentions.members.first();
        let msg = args.slice(1).join(" ");
      
        message.channel.createWebhook(usermentioned.displayName, 
        usermentioned.user.displayAvatarURL).then(wb =>        
          {       
            var Hook = new hookcord.Hook()
            .setLink(`https://discordapp.com/api/webhooks/${wb.id}/${wb.token}`)
            .setPayload({ 
              'title': usermentioned.displayName,
              'avatar': usermentioned.user.displayAvatarURL,
              'content': msg
          })
          .fire()
          .then(function(response)
           {
            wb.delete();
        }) 
          .catch(function(e) {})
      })
    }

错误:

message.channel.createWebhook(user提到.displayName, user提到.user.displayAvatarURL).then(wb => ^ TypeError:无法读取未定义的属性“displayName”

【问题讨论】:

    标签: javascript discord


    【解决方案1】:

    首先,您应该尝试使用调试器运行并跟踪您的变量用户提及。或者将此变量输出到控制台。它为您提供有关用户配置文件结构的信息。可能是您的个人资料级别错误

    【讨论】:

      猜你喜欢
      • 2021-04-25
      • 1970-01-01
      • 2021-05-17
      • 2021-02-07
      • 2012-07-11
      • 2020-10-09
      • 2021-12-03
      • 1970-01-01
      • 2021-04-13
      相关资源
      最近更新 更多