首页 > 解决方案 > 当它应该持续循环时,for循环不起作用

问题描述

async def helper():
a = "SELECT username FROM stoccssss"
cursor.execute(a)
people = cursor.fetchall()
for x in people:
    cursor.execute("SELECT stock_selected FROM stoccssss WHERE username=%s", (x))
    thingy = cursor.fetchall()
    balls = ' '.join(map(str, thingy))
    stockthingy = str(balls).replace('[', '')
    stockthingy1 = str(stockthingy).replace(']', '')
    stockthingy2 = str(stockthingy1).replace('(', '')
    stockthingy3 = str(stockthingy2).replace(')', '')
    stockthingy4 = str(stockthingy3).replace("'", '')
    stockthingy5 = str(stockthingy4).replace(",", "")
    stockTicker = yf.Ticker(stockthingy5.upper())
    hmm = stockTicker.history(period='5m')
    hmm = hmm.reset_index()
    test = str(hmm['High']).split()
    price = str(test[1])
    cursor.execute("SELECT money_amount FROM stoccssss WHERE username=%s", (x))
    moneycap = cursor.fetchone()
    moneycap = str(moneycap).replace('(', '')
    moneycap = str(moneycap).replace(')', '')
    moneycap = str(moneycap).replace(',', '')

    if moneycap < price:
        cursor.execute("SELECT username FROM stoccssss WHERE username=%s", (x))
        user = cursor.fetchone()
        user = str(user).replace('(', '')
        user = str(user).replace(')', '')
        user = str(user).replace(',', '')
        user = str(user).replace("'", '')
        user = client.get_user(int(user))
        await user.send("YOUR STOCK HAS SURPASSED YOUR PRICE OF " + str(moneycap) + " POG")
        return


    else:
        cursor.execute("SELECT username FROM stoccssss WHERE username=%s", (x))
        user = cursor.fetchone()
        user = str(user).replace('(', '')
        user = str(user).replace(')', '')
        user = str(user).replace(',', '')
        user = str(user).replace("'", '')
        user = client.get_user(int(user))
        await user.send("YOUR STOCK HAS GONE LOWER THAN YOUR PRICE OF " + str(moneycap) + " POG")
        return

await asyncio.sleep(5)


@client.event
async def on_ready():
    print("running")
    await helper()

该代码旨在在股票高于或低于某个价格时向某人发送消息,但由于某种原因,该代码只运行一次,再也不会运行

有谁知道这里发生了什么?

在此处添加文本,因为它要求我提供更多详细信息,但我不知道还能说什么,因此请忽略最后一行文本

是的,代码缩进正确,stackoverflow搞砸了

标签: pythondiscorddiscord.py

解决方案


你没有把 helper() 放在一个循环中,只是在做

while True:
  helper()

应该做的伎俩。


推荐阅读