简体   繁体   中英

Can someone tell me what am I doing wrong?

I am trying to make an alarm discord bot using python. No errors are happening, but also no output from the bot past the try, except function

Please note: alarm, not timer

@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")

If the error is happening in the try... except, you won't see anything. Try this instead:

        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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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