G
G
Goshujin2021-02-21 01:24:43
Python
Goshujin, 2021-02-21 01:24:43

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

3 answer(s)
S
Saboteur, 2021-02-21
@saboteur_kiev

https://pythonworld.ru/tipy-dannyx-v-python/fajly-...

D
David on the headstock, 2021-02-21
@davGro

It is better not to store anything in files, but to create a table in the database with columns banTimeStart memberUid reason authorOfBan durationand channel.
banTimeStartit 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 unbannedwhere 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()))

This query will display data about banned people whose ban time has already expired

K
Kirill, 2021-02-23
@KIRIK12

Isn't it easier to set the ban time in the ban options using the built-in function?
Documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question