Discord.py:如何重新启动和停止任务?

时间:2020-03-21 19:37:51

标签: discord.py discord.py-rewrite

@tasks.loop(minutes=1)
async def FunctionTask():
    print("Task running")

@client.event
async def on_ready():
    FunctionTask.start()

@client.command()
async def start(ctx):
    FunctionTask.restart()

@client.command()
async def start(ctx):
    FunctionTask.stop()

我正在尝试停止并重新启动任务,但出现错误。我做错了什么?预先谢谢你

编辑:添加了错误代码

Traceback (most recent call last):
  File "Test.py", line 39, in <module>
    async def start(ctx):
  File "C:\Users\Vortex\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 1163, in decorator
    self.add_command(result)
  File "C:\Users\Vortex\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 1071, in add_command
    raise discord.ClientException('Command {0.name} is already registered.'.format(command))
discord.errors.ClientException: Command start is already registered.

1 个答案:

答案 0 :(得分:-1)

您实际上已经两次执行了启动命令

stdout

@ client.command() 异步def start(ctx): FunctionTask.restart()

@ client.command() 异步def starta(ctx): FunctionTask.stop()```