在每个 GUILD discord.py 的每个频道上执行循环开始

Execute loop start on every channel for every GUILD discord.py

我制作了一个机器人命令,它有一个每小时循环一次的任务,它会被执行 on_ready 然后它就会循环。 但是,如果我的机器人在多台服务器上,这只会在一台服务器上执行。 有没有办法让它在所有服务器上工作?

我尝试了以下方法,但似乎没有用.)

@bot.event
async def on_ready():
    await bot.wait_until_ready()

    guilds = bot.guilds
    for guild in guilds:
        for channel in guild.channels:
            if channel.name == "bot-commands":
                allFloors.start(channel)

如何让 allFloors.start() 函数在其所属的每个服务器上作为循环工作?

对于上下文,我的所有楼层都是这样设置的

@tasks.loop(minutes=60)
async def allFloors(ctx):
    #Logic
    await ctx.send("Test")

所有其他命令(顺便说一句,bot.command() 在两台服务器上都可以正常工作) 如果在机器人被添加到任何服务器时开始这将是理想的吗?也许我看错了方法?在文档中找不到任何内容

这将启动一个任务,该任务在机器人上线时每小时运行一次。该任务将遍历机器人所属的所有公会中名称为 bot-commands 的所有频道,并发送一条消息 Test.

@tasks.loop(minutes=60)
async def allFloors():
    for guild in bot.guilds:
        for channel in guild.channels:
            if channel.name == "bot-commands":
                await channel.send("Test")


@bot.event
async def on_ready():
    allFloors.start()