Answer the question
In order to leave comments, you need to log in
How to make ban logs?
You need to make a file in which the bot will write banned users, and even after the restart he knew that he needed to unban him after the specified time, at the moment the bot can only do this:
@Bot.command()
@commands.has_permissions(administrator = True)
async def ban(ctx,member:discord.Member,time:int,reason):
await ctx.channel.purge(limit = 1)
emb = discord.Embed(title=f"{member.display_name}#{member.discriminator} Был забанен с сервера.", color=0xff0000)
emb.add_field(name="Модератор",value=ctx.message.author.mention)
emb.add_field(name="Пользователь",value=member.mention)
emb.add_field(name="Причина",value=reason)
emb.set_thumbnail(url="https://i.imgur.com/K2GwJCd.png")
emb.add_field(name="Длительность блокировки (Минут)",value=time)
await ctx.send(embed = emb)
await member.ban()
await asyncio.sleep(time * 60)
emb = discord.Embed(title=f"{member.display_name}#{member.discriminator} Был разбанен по истечению времени блокировки.", color=0xff0000)
await ctx.send(embed = emb)
await member.unban()
Answer the question
In order to leave comments, you need to log in
It is better not to store anything in files, but to create a table in the database with columns banTimeStart
memberUid
reason
authorOfBan
duration
and channel
.
banTimeStart
it int(time.time())
at the moment of entering of record in the table.
You can remove unbanned people from the table, or you can add a column unbanned
where it will be 0 if the person is still in the ban and 1 if the person is unbanned.
Every minute (or more often, at your discretion) make a request to the database like
from time import time
...
cursor.execute("""SELECT memberUid, channel from bans where banTimeStart + duration <= {0}""".format(int(time()))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question