等待具有 for 循环语法错误的函数
Await a function that has a for loop syntax error
我正在尝试让 discord 机器人能够在用户键入 'uploadAll' 时从文件夹上传所有图像。代码是:
def get_image(path):
image_list = []
for filename in glob.glob(path): #appends opened images from folder
im = Image.open(filename) #into list image_list and returns it
image_list.append(im)
return image_list
async def iter_image(path): #uploads images in the list
for i in get_image(path):
client.send_file(discord.Object(id='SERVER_ID'),i)
@client.command(pass_context=True)
async def uploadAll(self): #Should trigger above method
await iter_image('PATH_TO_FOLDER')
最后一个函数的结果是:
TypeError: object NoneType 不能在 'await' 表达式中使用。我不能等待 iter_image 因为它有一个 for 循环。关于如何获得事件循环来触发 for 循环的任何解决方案?谢谢
我很确定如果您在此处添加 await
它应该可以工作
await client.send_file(discord.Object(id='SERVER_ID'), i)
我正在尝试让 discord 机器人能够在用户键入 'uploadAll' 时从文件夹上传所有图像。代码是:
def get_image(path):
image_list = []
for filename in glob.glob(path): #appends opened images from folder
im = Image.open(filename) #into list image_list and returns it
image_list.append(im)
return image_list
async def iter_image(path): #uploads images in the list
for i in get_image(path):
client.send_file(discord.Object(id='SERVER_ID'),i)
@client.command(pass_context=True)
async def uploadAll(self): #Should trigger above method
await iter_image('PATH_TO_FOLDER')
最后一个函数的结果是: TypeError: object NoneType 不能在 'await' 表达式中使用。我不能等待 iter_image 因为它有一个 for 循环。关于如何获得事件循环来触发 for 循环的任何解决方案?谢谢
我很确定如果您在此处添加 await
它应该可以工作
await client.send_file(discord.Object(id='SERVER_ID'), i)