Discord bot 与 yfinance,属性错误

原文标题Discord bot with yfinance, attribute error

我最近一直在用 discord.py 制作一个不和谐的机器人,目的是用它来提供有关命令的股票信息。

我已经能够毫无问题地使用 TA_handler.py 和 discord.py,但是当我想使用 yfinance 从 yahoo Finance 中提取信息时,出现以下错误:

AttributeError: 'Ticker' object has no attribute 'floatShares'

编辑:忘了提,但不用说所有东西都是进口的,我只是没有在帖子中包含它

无论我尝试在股票行情上使用什么,无论我尝试使用什么方式,我都会得到这个,例如,我制作了这个较小的测试命令来显示在这里:

async def on_message(message):
    def check(m):
        return m.content == m.content and m.channel == message.channel
    if message.author == client.user:
        return
    obj = yf.Ticker('AAPL')
    obj_display = obj.floatShares
    await message.channel.send("{}".format(obj_display))

#This displays the error and I have no idea how I'm using it improperly, here is my other main example:

@client.command(name = "float")
async def on_message(message):
    def check(m):
        return m.content == m.content and m.channel == message.channel
    if message.author == client.user:
        return
    await message.channel.send('Please input a ticker')
    tGrab = await client.wait_for("message", check = check, timeout =30)
    tGrab = tGrab.content
    obj = yf.Ticker(tGrab)
    obj_Display = obj.floatShares
    await message.channel.send("{}".format(obj_Display))

原文链接:https://stackoverflow.com//questions/71918765/discord-bot-with-yfinance-attribute-error

回复

我来回复
  • SomeGuy74的头像
    SomeGuy74 评论

    好的,所以我有点傻,但我想通了,所以你必须先获取股票的整个信息摘要,然后才能获取特定值,这很奇怪,但就是这样。

    这是 AAPL 的示例代码,但工作正常:

    @client.command(name = "t")
    async def on_message(message):
        def check(m):
            return m.content == m.content and m.channel == message.channel
        if message.author == client.user:
            return
        obj = yf.Ticker('AAPL')
        obj_infograb = obj.info
        floatgrab = obj_infograb['floatShares']
        await message.channel.send("{}".format(floatgrab))
    
    2年前 0条评论