[英]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.