我怎么称呼不和.py对列表中的每一项执行多次函数?

2024-05-01 21:42:11 发布

您现在位置:Python中文网/ 问答频道 /正文

Im使用python中的discordapi来管理discord bot。此命令创建某个不和谐频道中的人员列表。在

我有一个功能:

async def attendance(ctx, channel):
    code here that creates a variable with member names
    await bot.say(printdiscordnames)

我想每次都用列表中不同的通道名调用上面的函数

所以我会这样做:

^{pr2}$

基本上我想做!attendanceall in discord,它将执行第一个函数,生成一个列表,并在discord中为列表中的每个频道打印它。在

我的问题是我不知道如何为列表中的每个频道名调用第一个函数。在


Tags: 函数命令功能列表async人员defbot
2条回答
async def attendanceall(ctx):
channel_list = ['voice1', 'voice2', 'voice3']
for item in channel_list:
    asyncio.get_event_loop().create_task(attendance(item))

您可以这样做来运行一个异步函数,或者使用下面的方法来运行它

^{pr2}$

尝试:

async def attendanceall(ctx):
    channel_list = ['voice1', 'voice2', 'voice3']
    for item in channel_list:
        await attendance(item)

请参阅this链接以获取帮助

相关问题 更多 >