如何解决在 Python 中的一组固定时间发送消息
本质上,我正在寻找一种在添加到 times.json 的所有时间发送倒计时消息的方法
我已经设法让函数每隔几秒发送一次,但我想在固定时间发送它
@fb.command(name="send")
async def send(ctx,time,countdown,*,message):
if ctx.author.id == 534473265574314003:
WAIT_TIME_SECONDS = int(countdown)
ticker = threading.Event()
while not ticker.wait(WAIT_TIME_SECONDS):
await sendMessage(message)
else:
await ctx.channel.send("You don't have permission for that command!")
@fb.group(name="timer",invoke_without_command=True)
async def timer(ctx):
await ctx.channel.send("Tr !fb help")
@timer.command(name="add")
async def add(ctx,newtime):
with open('times.json') as json_file:
data = json.load(json_file)
addtime = datetime.strptime(newtime,'%H:%M:%S')
addtime = addtime.strftime('%H:%M:%S')
data['times'].append({
'time':addtime
})
with open("times.json","w") as f:
json.dump(data,f)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。