无法在调用中执行命令 #24
无法在调用中执行命令
#24
-
我在做一个群聊投票裁决机器人,但是它需要sleep,而在这期间无法调用,机器人发消息:“您有命令正在执行,请稍后再试”,请问如何解决这个问题 # -*- coding:utf-8 -*-
import asyncio
from nonebot import on_command, CommandSession
from nonebot.permission import *
from aiocqhttp import MessageSegment
judged_persons=[]
judge_var={}
@on_command('judge_apply', aliases=('裁决申请','申请裁决'),only_to_me=False,permission=EVERYBODY)
async def judge_apply(session: CommandSession):
if len(session.event["message"])!=2:
await session.send(message=MessageSegment.at(session.event['user_id']) + '请输入"裁决申请 类型 @某人"或者"申请裁决 类型 @某人"')
return
p1 = str(session.event["message"][0]).split(" ")[1]
p2 = session.event["message"][1]
if p2["type"] != "at":
await session.send(message=MessageSegment.at(session.event['user_id'])+'请输入"裁决申请 类型 @某人"或者"申请裁决 类型 @某人"')
return
if p1=="禁言":
judge_var[str(p2['data']['qq'])] = {"yes": 0, "no": 0, "class": "禁言"}
elif p1=="踢出":
judge_var[str(p2['data']['qq'])] = {"yes": 0, "no": 0, "class": "禁言"}
else:
await session.send(MessageSegment.at(session.event['user_id']) + "类型只有禁言和踢出")
return
await session.send(MessageSegment.at(session.event['user_id']) + "成功申请裁决\n" + '输入"支持裁决 @被裁决人"支持裁决\n' + '输入"反对裁决 @被裁决人"反对裁决\n' + "裁决将在3分钟后判决")
await asyncio.sleep(3*60)
await session.send(str(judge_var))
@on_command('judge_apply_yes', aliases=('支持裁决'),only_to_me=False,permission=EVERYBODY)
async def judge_apply_yes(session: CommandSession):
at_p = session.event["message"][1]
if len(session.event["message"])!=2 and at_p["type"] != "at":
await session.send('请输入"支持裁决 @被裁决人"')
return
await session.send(MessageSegment.at(session.event['user_id'])+"成功支持裁决") 求解答 |
Beta Was this translation helpful? Give feedback.
Answered by
mnixry
Aug 17, 2021
Replies: 2 comments 3 replies
-
你可以用 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
stdrc
-
直接把 sleep 放到单独的 async 函数里,然后直接 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你可以用
loop.call_later
来创建一个在一定时间后调用的异步回调