如何解决如何运行调度程序以便其他功能在 discord.py 中工作
我认为时间表不会干扰机器人命令,但它确实会干扰。在我运行计划后,假设每分钟一次,它会阻止我的机器人中的其他功能。我正在寻找一种解决方案来通过调度程序运行 1 个简单任务(我正在使用 this schedule 模块)并保留所有主要的机器人功能 - 任何命令或事件。
示例:
let fips = id['ParamValues'].find(o=>o.param==='fips')['value'];
let region = id['ParamValues'].find(o=>o.param==='region')['value'];
//code change
let params = {};
fips.length > 0 ? params['fips'] = fips.join(',') : null;
region != 0 ? params['region'] = region : null;
//code change
axios.get('https://educationdata.urban.org/api/v1/college-university/ipeds/directory/2019/',{
params
}).then(response=>{
console.log(response.data.results);
});
我希望运行 @client.event
async def on_message(message):
if message.author.id == xxxxx:
print("im working")
def test():
print("hello")
job = schedule.every().second.do(test)
while 1:
schedule.run_pending()
函数并能够同时通过 test
函数检测消息。
感谢您的帮助
解决方法
Discord.py 有一个功能,see the full documentation here。这是一个简短的例子:
from discord.ext import tasks
@tasks.loop(seconds=5)
async def foo():
print('This function runs every 5 Seconds')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。