繁体   English   中英

如何运行 create a discord.py bot 命令,该命令将使用不同的参数多次运行另一个 bot 命令?

[英]How do I run create a discord.py bot command that will run another bot command multiple times with different parameters?

我有一个命令是 !attendance channel,其中 channel 是您要阅读的语音频道。 然后,机器人不和谐地打印该频道中的成员列表。

我的问题是,是否有一种方法可以获得频道列表,并让机器人通过 1 个命令运行每个频道。 例如,执行 !attendanceall 并让机器人在列表中为 !attendance 命令提供 3 个不同的频道。

我试过发出另一个命令并调用出勤命令,但它不起作用。

@bot.command(pass_context = True)
async def attendanceall(ctx):
    voice_list = ['channel1', 'channel2']
    for item in voice_list:
        attendance(item)

# the start of the attendance command if the variables matter
bot.command(pass_context = True)
async def attendance(ctx, channel : str = None, useDiscordID : bool = False):
    # the code that creates a list of all members goes here that isnt important
    # eventually I tell the bot to send the list of members
    await ctx.send(attendancelist)

我想要一个名为 voice_list 的固定列表,当使用 !attendanceall 命令时,它会 ping !attendance 命令并为每个列表项运行它。

将您正在执行的任何操作的逻辑与命令分开可能会更好。 因此,如果您有在特定频道或所有频道上执行某些操作的命令,则可能如下所示:

@bot.command()
async def do_to_all(ctx):
    for channel in ctx.guild.channels:
        await do_thing(channel)

@bot.command()
async def do_for_channel(ctx, channel: discord.GuildChannel):
    await do_thing(channel)

async def do_thing(channel):
    ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM