[英]Is await Asyncio.sleep inconsistent?
As the title says, is await asynco.sleep
inconsistent?正如标题所说,
await asynco.sleep
不一致? As you can see from my code below, my code is meant to wait 24hrs, then send a private message to the user.从下面的代码中可以看出,我的代码是要等待 24 小时,然后向用户发送私人消息。 From multiple tests I have ran, the code does work if I set a short time (I have tested, 1, 2,3 min all the way up to 10 min).
从我运行的多个测试中,如果我设置了很短的时间(我已经测试过,1、2,3 分钟一直到 10 分钟),代码确实可以工作。 However, I would like it set for 24hrs.
但是,我希望它设置为 24 小时。
A bit of background on how the code is ran.关于如何运行代码的一些背景知识。 I use replit and use uptime robot to ping the server to make sure it stays active.
我使用 replit 并使用 uptime 机器人来 ping 服务器以确保它保持活动状态。 The bot does function as normal 24/7 apart from this await.
除了等待之外,该机器人 24/7 照常执行 function。
So, is it that await Asyncio.sleep
only works consistently for smaller periods of time, or is it the way I am running the code, ie through replit and uptime bot?那么,是
await Asyncio.sleep
仅在较短的时间内始终如一地工作,还是我运行代码的方式,即通过 replit 和 uptime 机器人? My reason to think it could maybe be uptime bot, is I assume, if it doesnt ping, the bot turns off?我有理由认为它可能是正常运行时间机器人,我是否假设,如果它不 ping,机器人会关闭? Making it re-run the code?
让它重新运行代码? My only thought to why it can't be that is that replit's seem to stay online for 5 minute without being pinged by uptime bot.
我唯一想到的原因是,replit 似乎保持在线 5 分钟而没有被正常运行时间机器人 ping。 So if uptime bot does not ping, i'd assume the Replit has some leway.
因此,如果正常运行时间机器人没有 ping,我会假设 Replit 有一些余地。 Also, if it did happen to turn off, it would mean I would have to manually turn it back on etc. However, as I mentioned above, the rest of the code works 24/7 so I'm really lost!
此外,如果它确实关闭了,这意味着我将不得不手动重新打开它等等。但是,正如我上面提到的,代码的 rest 24/7 工作,所以我真的迷路了!
If anyone has any advice for this novice, I would greatly appreciate it!如果有人对这个新手有任何建议,我将不胜感激!
Cheers!干杯!
@client.event
async def on_member_join(member):
channel = client.get_channel(*Discord channel id*)
embed=discord.Embed(title=f"**Welcome**: {member.name}", description=f"Thanks for joining {member.guild.name}! :partying_face:",color=0x7DF9FF) # F-Strings
embed.add_field(name=" __**To get started:**__", value="Head over to #rules and #faq :smile:", inline=True)
embed.add_field(name=" __**How to sell and trade**__", value="you will be added to a 24hr timer, after that peroid you will have access to the sell and trade rooms", inline=True)
embed.set_thumbnail(url=member.avatar_url) # Set the embed's thumbnail to the member's avatar image!
await asyncio.sleep(1)
await channel.send(embed=embed)
#this acts as a pause, and will count up to the time entered in secconds before executing the rest of the script
await asyncio.sleep(86400)
#This bit gives members a specific role
role = get(member.guild.roles, name="Supporter")
await member.add_roles(role)
#THIS BIT SENDS MEMBERS A MESSAGE ALERTING THEM OF THEIR NEW ROLE
await member.create_dm()
await member.dm_channel.send(f'Hi {member.name}, Congratulations :partying_face: you have now unlocked the trade and sell rooms, please read #rules and #faq before making a post')`
It is perfectly accurate, replit just messes it up.这是完全准确的,replit只是把它搞砸了。 You really shouldn't be using replit as a hosting service because it restarts all the time, interrupting async processes.
您真的不应该将 replit 用作托管服务,因为它一直在重新启动,从而中断异步进程。 Use a VPS.
使用 VPS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.