【问题标题】:Why i"m having this error: (node:16040) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'title' of undefined为什么我有这个错误:(节点:16040)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“标题”
【发布时间】:2020-09-25 02:53:57
【问题描述】:

const Discord = require('discord.js') const riotapi = require('../botconfig.json')

const fetch = require("node-fetch");

const querystring = require('querystring');

module.exports.run = async (client, message, args) => { 常量冠军 = args[0]

    const Curl = `http://ddragon.leagueoflegends.com/cdn/10.11.1/data/pt_BR/champion/${champ}.json`
    const imgUrl = `http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/${champ}.png`

    console.log(Curl)

    message.channel.send("Procurando pelo campeão: " + champ).then(message => message.delete({timeout: 1000}))

    fetch(Curl)
        .then(res => res.json())    
        .then(champS => {
            let champEmbed = new Discord.MessageEmbed()
            .setTitle(`${champ}`)
            .setDescription(`${champS.data.champ.title}`)
            .addField("Classe", `${champS.data.champ.tags}`)
            .addField("Dicas para aprimorar as fights!", `${champS.data.champ.enemytips}`)
            .addField("Dicas para ajudar o time!", `${champS.data.champ.allytips}`)
            .addField("Passiva", `${champS.data.champ.passive.description}`)
            .setThumbnail(imgUrl)
            .setColor("RED")
            .setFooter("Grandmaster, by: IgorDuca")

            message.channel.send(champEmbed)
        })
}

【问题讨论】:

  • 因为champS.data.champ 未定义。请查看Curl的回复
  • 这是因为我试图使用它的名字来获取冠军的礼仪,在这种情况下,args[0]

标签: javascript api discord.js


【解决方案1】:

试试embed.setTitle或访问这个网站来定义它

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_defined

【讨论】:

  • 错误不在嵌入中,而是在请求中,因为当我尝试使用 champS.data.Yasuo.id 时,它可以工作并获取冠军亚索的 id,但是当我用的是championS.data.champion.id 它不起作用,因为它可以得到id的适当性,OBS(champ = args[0])
猜你喜欢
  • 1970-01-01
  • 2021-10-10
  • 2020-08-18
  • 2020-12-11
  • 1970-01-01
  • 2020-12-27
  • 2022-01-11
  • 2019-12-15
  • 2021-08-31
相关资源
最近更新 更多