循环中的Context是否可能不和谐.py



我有一个自动通道删除程序,它使用commands.task.loop()来检查自上次发送消息以来经过的时间。循环函数有我自己的自定义函数,它需要Context(这个自定义函数使用awaitcommands.EmojiConverter().convert(),它需要Context作为其参数之一(

我不知道我是否需要发送代码,但我认为我写的已经足够好了,希望

通过调用start方法启动循环时,可以向它传递任何您想要的参数。例如:

class Test(commands.Cog):
@tasks.loop(seconds=2)
async def spammer(self, ctx: commands.Context):
await ctx.send(".")
@commands.command()
async def start(self, ctx):
self.spammer.start(ctx)

通过将这个cog添加到您的bot,您可以使用start命令开始一个名为spammer的循环,该循环将具有该命令的上下文,因为它是作为参数传递给start方法的:self.spamer.start(ctx)

如果您还有任何问题,请随时在评论中提问:(

最新更新