繁体   English   中英

有人可以告诉我我做错了什么吗?

[英]Can someone tell me what am I doing wrong?

我正在尝试使用 python 发出警报 discord 机器人。 没有发生错误,但也没有来自机器人的 output 经过尝试,除了 function

请注意:闹钟,不是定时器

@client.command(aliases = ["alarm"])
async def alarm_at(ctx, time):
    alarm = False
    if alarm == False:
        alarm = True
        now = datetime.now()
        mtimeA = time
        mtimeB = mtimeA.split(":")
        hr = int(mtimeB[0])
        min = int(mtimeB[1])
        secsleft = int((timedelta(hours=24) - (now - now.replace(hour=hr, minute=min, second=0, microsecond=0))).total_seconds() % (24 * 3600))
        print(secsleft)
        await ctx.send(f"OK\Alarm go off at {time}")

        def check(message):
            return message.author == ctx.author and message.content.lower() == "cancel alarm"
        try:
            await client.wait_for("message", check=check, timeout=time)
            await ctx.send("alarm cancelled")
        except:
            if secsleft == 0:
                await ctx.send(f"{ctx.guild.default_role} alarm finished")
    elif alarm == True:
        await ctx.send("Please cancel the current alarm to run a new alarm")

如果在尝试中发生错误...除了,您将看不到任何东西。 试试这个:

        try:
            await client.wait_for("message", check=check, timeout=time)
            await ctx.send("alarm cancelled")
        except Exception as e:
            print(f"Error: {e}")
            if secsleft == 0:
                await ctx.send(f"{ctx.guild.default_role} alarm finished")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM