简体   繁体   English

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

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

I am trying to make an alarm discord bot using python.我正在尝试使用 python 发出警报 discord 机器人。 No errors are happening, but also no output from the bot past the try, except function没有发生错误,但也没有来自机器人的 output 经过尝试,除了 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")

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

相关问题 有人可以告诉我我做错了什么新到 Python - Can someone please tell me what am I doing wrong New to Python 有人可以告诉我我做错了什么[暂停] - Can someone tell me what I'm doing wrong [on hold] 我不明白为什么这段代码不起作用! 有人可以告诉我我做错了吗? - I don't see why this code is not working! can someone please tell me what i am doing wrong? 有人可以告诉我我的代码有什么问题吗? 我在调试时遇到问题 - Can someone tell me what is wrong with my code? I am having problems debugging 谁能告诉我我做错了什么,字典与 Python 中的列表? - Can anyone tell me what I am doing wrong, dictionary vs list in Python? 有人能告诉我我做错了什么吗? 它一直说 meal_cost is not defined - Can someone tell me what im doing wrong? it keeps saying meal_cost is not defined 有人可以告诉我这个 python 代码哪里错了吗? - Can someone please tell me where am I wrong in this python code? 有人能告诉我出了什么问题,当我运行它时,浏览器说“无法访问此站点” - Can someone tell me what's wrong, when I run it the browsers says "This site can’t be reached" 有人能告诉我这个 python 代码有什么问题吗? - Can someone tell me what is wrong with this python code? 有人能告诉我我的代码有什么问题吗 - Can someone tell me what is wrong with my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM