Команда мут, а так-же размут работает прекрасно, но не понимаю почему не работает команда бан, она вносит данные, но проверки которые существуют она пропускает и не разбанивает пользователя.
database_handler.py
import os
import sqlite3
import datetime
class DatabaseHandler():
def __init__(self, database_name : str):
self.con = sqlite3.connect(f"{os.path.dirname(os.path.abspath(__file__))}/{database_name}")
self.con.row_factory = sqlite3.Row
def add_tempmute(self, user_id : int, guild_id : int, expiration_date : datetime.datetime):
cursor = self.con.cursor()
query = "INSERT INTO Tempmute (user_id, guild_id, expiration_date) VALUES (?, ?, ?);"
cursor.execute(query, (user_id, guild_id, expiration_date))
cursor.close()
self.con.commit()
def active_tempmute_to_revoke(self, guild_id : int) -> dict:
cursor = self.con.cursor()
query = f"SELECT * FROM Tempmute WHERE guild_id = ? AND active = 1 AND expiration_date < ?;"
cursor.execute(query, (guild_id, datetime.datetime.now()))
result = list(map(dict, cursor.fetchall()))
cursor.close()
return result
def revoke_tempmute(self, tempmute_id : int):
cursor = self.con.cursor()
query = f"UPDATE Tempmute SET active = 0 WHERE id = ?;"
cursor.execute(query, (tempmute_id,))
cursor.close()
self.con.commit()
def un_tempmute(self, user_id : int):
cursor = self.con.cursor()
query = f"UPDATE Tempmute SET active = 0 WHERE user_id = ?;"
cursor.execute(query, (user_id,))
cursor.close()
self.con.commit()
def add_ban(self, user_id : int, guild_id : int, expiration_date : datetime.datetime):
cursor = self.con.cursor()
query = "INSERT INTO Ban (user_id, guild_id, expiration_date) VALUES (?, ?, ?);"
cursor.execute(query, (user_id, guild_id, expiration_date))
cursor.close()
self.con.commit()
def active_ban_to_revoke(self, guild_id : int) -> dict:
cursor = self.con.cursor()
query = f"SELECT * FROM Ban WHERE guild_id = ? AND active = 1 AND expiration_date < ?;"
cursor.execute(query, (guild_id, datetime.datetime.now()))
result = list(map(dict, cursor.fetchall()))
cursor.close()
return result
def revoke_ban(self, ban_id : int):
cursor = self.con.cursor()
query = f"UPDATE Ban SET active = 0 WHERE id = ?;"
cursor.execute(query, (ban_id,))
cursor.close()
self.con.commit()
def un_ban(self, user_id : int):
cursor = self.con.cursor()
query = f"UPDATE Ban SET active = 0 WHERE user_id = ?;"
cursor.execute(query, (user_id,))
cursor.close()
self.con.commit()
bot.py
@client.command(aliases = ['mute'])
async def мут(ctx, member : discord.Member, time: str = None, *, reason = None):
if member is None:
return await ctx.reply("Укажите пользователя которому желаете выдать наказание!")
if time is None:
return await ctx.reply("Укажите длительность блокировки")
else:
try:
seconds = int(time[:-1])
duration = time[-1]
if duration == "s":
pass
if duration == "m":
seconds *= 60
if duration == "h":
seconds *= 3600
if duration == "d":
seconds *= 86400
except:
return await ctx.send("Укажите формат (s,m,h,d)")
muted_role = await get_muted_role(ctx.guild)
database_handler.add_tempmute(member.id, ctx.guild.id, datetime.datetime.now() + datetime.timedelta(seconds=int(seconds)))
mute_time = (datetime.datetime.now() + datetime.timedelta(seconds=int(seconds))).strftime("%c")
await member.add_roles(muted_role)
embed=discord.Embed(title="**Модерация PteroHost.com**", description="Огромная просьба не нарушайте правила нашего Discord-сообщества", color=0x0091ff)
embed.add_field(name="Нарушитель", value=f"{member.mention}", inline=True)
embed.add_field(name="Тип наказания", value="Мут", inline=True)
embed.add_field(name="Причина", value=f"{reason}", inline=True)
embed.add_field(name="Длительность блокировки", value=f"{mute_time}", inline=True)
embed.set_footer(text="@ PteroHost.com")
await ctx.send(embed=embed)
@client.command(aliases = ['ban'])
async def бан(ctx, member : discord.Member, time: str = None, *, reason = None):
if member is None:
return await ctx.reply("Укажите пользователя которому желаете выдать наказание!")
if time is None:
return await ctx.reply("Укажите длительность блокировки")
else:
try:
seconds = int(time[:-1])
duration = time[-1]
if duration == "s":
pass
if duration == "m":
seconds *= 60
if duration == "h":
seconds *= 3600
if duration == "d":
seconds *= 86400
except:
return await ctx.send("Укажите формат (s,m,h,d)")
database_handler.add_ban(member.id, ctx.guild.id, datetime.datetime.now() + datetime.timedelta(seconds=int(seconds)))
ban_time = (datetime.datetime.now() + datetime.timedelta(seconds=int(seconds))).strftime("%c")
await member.ban(reason=reason)
embed=discord.Embed(title="**Модерация PteroHost.com**", description="Огромная просьба не нарушайте правила нашего Discord-сообщества", color=0x0091ff)
embed.add_field(name="Нарушитель", value=f"{member.mention}", inline=True)
embed.add_field(name="Тип наказания", value="Бан", inline=True)
embed.add_field(name="Причина", value=f"{reason}", inline=True)
embed.add_field(name="Длительность блокировки", value=f"{ban_time}", inline=True)
embed.set_footer(text="@ PteroHost.com")
await ctx.send(embed=embed)
@client.command(aliases = ['unmute'])
async def размут(ctx, member : discord.Member, *, reason = None):
if member is None:
return await ctx.reply("Укажите пользователя которому желаете выдать наказание!")
else:
muted_role = await get_muted_role(ctx.guild)
database_handler.un_tempmute
await member.remove_roles(muted_role)
embed=discord.Embed(title="**Модерация PteroHost.com**", description="Огромная просьба не нарушайте правила нашего Discord-сообщества", color=0x0091ff)
embed.add_field(name="Пользователь", value=f"{member.mention}", inline=True)
embed.add_field(name="Тип разжалования", value="Размут", inline=True)
embed.add_field(name="Причина", value=f"{reason}", inline=True)
embed.set_footer(text="@ PteroHost.com")
await ctx.send(embed=embed)
@tasks.loop(minutes=1)
async def check_for_unmute():
for guild in client.guilds:
active_tempmute = database_handler.active_tempmute_to_revoke(guild.id)
if len(active_tempmute) > 0:
muted_role = await get_muted_role(guild)
for row in active_tempmute:
member = guild.get_member(row["user_id"])
database_handler.revoke_tempmute(row["id"])
await member.remove_roles(muted_role)
@tasks.loop(seconds=5.0)
async def check_for_unban():
for guild in client.guilds:
active_ban = database_handler.active_ban_to_revoke(guild.id)
if len(active_ban) > 0:
for row in active_ban:
member = guild.get_member(row["user_id"])
database_handler.revoke_ban(row["id"])
await member.unban()
Пожалуйста помогите разобраться, что не так с моим кодом!