T
T
Telmor2021-10-17 18:49:25
Python
Telmor, 2021-10-17 18:49:25

How to make time saving through pymongo so that even if the bot is offline the time is running?

I have a ban code. At me removal of a role through opr is made. gap with await asincio.sleep. But there are problems with this. If the bot is turned off - everything is bugged. How to use Pymongo to enter the end time of the punishment (in the database) and check for the end. Those. if the time is now greater than the end of the punishment, then the command continues, or the role is removed.
I think it will not help much, but below is the code.
The code

@bot.command()
async def ban(ctx, member:discord.Member, time, *, arg):
    ban_role = discord.utils.get(ctx.author.guild.roles, id=896315064817168414)
    emb = discord.Embed(
        title='Бан',
        description=f'{ctx.author.mention}, вы **выдали** бан пользователю {member.mention}'
    )
    emb.add_field(namef='> **Время:**', value=f'```{time}```')
    emb.add_field(namef='> **Причина**', value=f'```{arg}```')
    emb.set_thumbnail(url=ctx.author.avatar_url)
    await ctx.send(embed=emb)
    await member.add_roles(ban_role)
    time = convert(time)
    await asyncio.sleep(time)
    await member.remove_roles(ban_role)

It would be desirable to receive the answer clear and with an example.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kadabrov, 2021-10-17
@Kadabrov

Add a column to the user's table ending the ban, and when entering the server the role of the ban, check the difference between the recorded time and the current one, if the delta is negative, then give the previous role before the ban or assign the desired one

K
kirillinyakin, 2021-10-17
@kirillinyakin

At least google how you can get banned here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question