首页 > 解决方案 > 调度 Discord Python 任务

问题描述

我已经阅读了很多文章,但似乎无法理解。我有一个不和谐的机器人和一个有效的 !news 命令。我想安排此任务每 5 分钟运行一次。下面的代码仍然设置为命令,我只是不确定要更改什么。提前致谢!

import all the modules

TOKEN = 'XXX'
description = ...
bot = commands.Bot(command_prefix="!")
client = discord.Client()

@bot.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')
  
def check(ctx):
    return lambda m: m.author == ctx.author and m.channel == ctx.channel

async def get_input_of_type(func, ctx):
    while True:
        try:
            msg = await bot.wait_for('message', check=check(ctx))
            return func(msg.content)
        except ValueError:
            continue

#other bot commands here, working fine
@bot.command(name='scores', help='starts prompts to retrieve LG league scores')
....

@bot.command(name='news')
async def news(ctx):
   #do stuff here, works fine for coommand
  
keep_alive()
bot.run(TOKEN)

标签: pythondiscord

解决方案


推荐阅读