python - 调度 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)
解决方案
推荐阅读
- javascript - Gulp watch 导致无限构建循环
- python-3.x - 我想遍历一些 IP 地址和网络,以检查 IP 是否属于特定网络
- c# - HTTPS代理实现,如何检测完成的请求
- docker - 尝试通过 UI 下载时,docker 中的 Artifactory 在文件中使用井号 (#) 获取 404
- php - Redis CLI 未通过 Laravel 显示最近存储的密钥
- .net-core - 使用移动浏览器的 IdentityServer 4 的 GrantType 隐式工作流
- python - 将“ActorHandler”保存在另一个演员中以供以后使用时发生错误
- php - 从 iMagick 到 PNG 的 PDF 质量很差
- c++ - `return_if(cond, val)` 不借助宏
- jms - ActiveMQ Artemis 计划消息卡住