【发布时间】:2020-08-07 04:27:57
【问题描述】:
我的目标是在 cog 内部调用函数时“切换”一个循环。我希望该函数采用文件名的参数。该函数将打印它从 txt 文件中读取的行。我希望它循环,直到我调用另一个取消它的函数。
Discord py 使用异步,我只是不知道如何在函数内操作循环。
示例:
class Looptest:
def __init__(self, client):
self.client = client
#This is responsible for playing the loop.
async def play_loop(self, filename):
filename = (path_to_txtfile)
#loop the following code
with open(filename, 'r') as f:
line = f.readlines()
print(line)
async def stop_loop(self):
#stop the loop
【问题讨论】:
标签: python python-3.x discord.py