【发布时间】:2021-03-06 00:11:03
【问题描述】:
我对数据库不太了解,我想为我的提醒命令和可变前缀做一个。对于前缀,我目前使用的是 json 文件,但有人说最好使用数据库。此外,我的提醒命令不存储提醒,因此当机器人关闭时,提醒就消失了。如果有人可以帮助我,我会很高兴。
这是我的提醒命令代码:
@commands.command(aliases=['remind','remindme'])
async def reminder(self, ctx, time, *, reminder):
user = ctx.message.author
embed = discord.Embed(colour=discord.Colour.gold())
seconds = 0
if reminder is None:
embed.add_field(name='❌ Wrong Usage', value='`reminder <duration> <reminder>` is the correct way to use this command.')
if time.lower().endswith("d"):
seconds += int(time[:-1]) * 60 * 60 * 24
counter = f"{seconds // 60 // 60 // 24} days"
if time.lower().endswith("h"):
seconds += int(time[:-1]) * 60 * 60
counter = f"{seconds // 60 // 60} hours"
elif time.lower().endswith("m"):
seconds += int(time[:-1]) * 60
counter = f"{seconds // 60} minutes"
elif time.lower().endswith("s"):
seconds += int(time[:-1])
counter = f"{seconds} seconds"
if seconds == 0:
embed.add_field(name='❌ Wrong Usage',
value='Please specify a proper duration')
elif seconds > 31536000:
embed.add_field(name='❌ Wrong Usage', value='You have specified a too long duration!\nMaximum duration is 365 days.')
else:
await ctx.send(f"Alright, I will remind you about `{reminder}` in `{counter}`.")
await asyncio.sleep(seconds)
await ctx.send(f"**Reminder** {user.mention}: {reminder}")
return
await ctx.send(embed=embed)```
【问题讨论】:
标签: python database sqlite discord.py discord.py-rewrite