Ajout de la commande pour envoyer un message en tant que personnage et création d'une fonction utilitaire pour récupérer les personnages d'un utilisateur

This commit is contained in:
GZod01 2024-12-15 15:45:33 +01:00
parent 04c4353a6b
commit 2c7fcb6fc5
2 changed files with 22 additions and 0 deletions

View file

@ -24,4 +24,23 @@ async def on_ready():
await bot.tree.sync()
print(f"Logged in as {bot.user}")
@bot.tree.command(name="s",description="Envoyer un message en tant que personnage",aliases=["say","dire","écrire"])
async def say(interaction:discord.Interaction,id:str,message:str):
res = await bot.db.execute("SELECT * FROM personnages WHERE uuid=? AND (guild_id=? OR guild_id IS NULL) AND nom_court=?",(interaction.user.id,interaction.guild.id,id))
row = await res.fetchone()
await res.close()
if row is None:
await interaction.response.send_message("Personnage non trouvé",ephemeral=True)
return
short_name = row[0]
full_name = row[1]
perso_image = row[2]
webhook = None
if discord.utils.get(interaction.channel.webhooks(),name=short_name) is None:
webhook = await interaction.channel.create_webhook(name=short_name,avatar=perso_image)
else:
webhook = discord.utils.get(interaction.channel.webhooks(),name=short_name)
await webhook.send(message,username=full_name,avatar_url=perso_image)
await interaction.response.send_message("Message envoyé",ephemeral=True)
bot.run(bot_token)

3
utils.py Normal file
View file

@ -0,0 +1,3 @@
async def get_user_persos(bot,user:int,guild_id:int):
async with bot.db.execute("SELECT * FROM personnages WHERE uuid=? AND (guild_id=? OR guild_id IS NULL)",(user,guild_id)) as cursor:
return await cursor.fetchall()