discord.py - Discord.py 临时禁令
问题描述
我只是想创建一个命令,如果我的机器人重新启动它仍然会取消禁止成员。这是我的代码:
@commands.command() # kihagyva
async def tempban(self, ctx, member: discord.Member,seconds: int, d,*,reason=None):
embed = discord.Embed(title="TempBanned",
description=f"{member.mention} has been tempbanned",
colour=discord.Colour.blue())
embed.add_field(name="reason:", value=reason, inline=False)
embed.add_field(name="time left for the ban:", value=f"{seconds}{d}", inline=False)
await ctx.send(embed=embed)
if d == "s":
await asyncio.sleep(seconds*1)
if d == "m":
await asyncio.sleep(seconds*60)
if d == "h":
await asyncio.sleep(seconds*60*60)
if d == "d":
await asyncio.sleep(seconds*60*60*24)
await member.unban()
embed = discord.Embed(title="unbanned (temp) ", description=f"unbanned {member.mention} ", colour=discord.Colour.blue())
await ctx.send(embed=embed)
解决方案
因此,您可以将其存储在数据库中,例如 sqlite、mysql/mariadb 或 mongodb。
在 MongoDB 中,您将拥有一个集合,该集合就像一个充满用户和行会 ID 以及禁令何时到期的表。
您将使用任务每分钟或 30 秒循环一次,或者可以更长。遍历数据库并检查time now
和time stored
是否小于time now
. 然后解禁他们。
推荐阅读
- python - 从 Github 下载的项目设置错误
- python - 如何使用 Python 禁用或启用 windows shield?
- amazon-web-services - 如何在 Docker 容器中运行命令
- r - 合并数据框并填充缺失值
- javascript - 如果放在“img”目录下,express.static 不提供静态文件(图像)
- javascript - 如何检查路径是文件还是目录
- javascript - socket.io 不允许 clearInterval 工作
- python - 以最“python 方式”从另一个列表中创建一个列表
- python - docker - 安装模块后的 ModuleNotFoundError
- angular - 如何在角度材料表中的嵌套对象内显示数据