I linked my database with a discord.py command so that when I send one command, the user can't re-send another one. This works because I record his id in the database, but if the user uses the command repeatedly the database fills up with his requests, so if I refresh the database through the code I can make his id be taken into account and not be bugged. Is there a way to fix this or to refresh a database via code? Thank you.
@bot.command()
async def clear(ctx, amount = 0):
time.sleep(1)
await ctx.channel.purge(limit=amount)
texto_final = discord.Embed(title= "Mensajes borrados correctamente :white_check_mark: ", description = f"{ctx.author.name} *tus mensajes se borraron correctamente.* **Mensajes borrados:** {amount}.", timestamp = datetime.datetime.utcnow(), color = discord.Color.green())
await ctx.send(embed = texto_final)
time.sleep(10)
await ctx.channel.purge(limit = 1)
#DNI Interfaz
async def on_BDLA(ctx):
return row[4] != ctx.author.id
@bot.command()
@commands.check(on_BDLA)
async def crear_dni(ctx):
respuesta = await bot.wait_for("message", timeout=60)
respuesta = respuesta.content.split(", ")
status = True
if status == False:
pass
elif status == True:
dni_info = discord.Embed(title = f"📇DNI de {ctx.author.name}", description= f"📄**Nombre** \n➥ *{respuesta[0]}* \n📄**Apellido** \n➥ *{respuesta[1]}* \n📅**Nacimiento** \n➥ *{respuesta[2]}* \n🏳️**Nacionalidad** \n➥ *{respuesta[3]}* \n🆔**ID** \n➥ *{ctx.author.id}*", color = discord.Color.purple() )
dni_info.set_image(url="https://media.discordapp.net/attachments/1052061231680344134/1053135738180472832/banner.png")
await ctx.send(embed = dni_info)
async with aiosqlite.connect("main.db") as db:
async with db.cursor() as cursor:
await cursor.execute(f"INSERT INTO users (nombre, apellido, nacimiento, nacionalidad, user_id) VALUES (?, ?, ?, ?, ?)", (respuesta[0], respuesta[1], respuesta[2], respuesta[3], ctx.author.id))
await db.commit()
con.close()```
1条答案
按热度按时间i86rm4rw1#
尽量不要对数据库命令使用异步
我的意思是使用普通的
sqlite3
库这会非常好用