Added defer when transcript & renamed the file with transcript_servername_channelname_dd-month-yyyy.txt

This commit is contained in:
Paillat
2022-12-12 12:55:13 +01:00
parent 1194f44092
commit 2f4495bf13

View File

@@ -60,14 +60,15 @@ class ManageChat (discord.Cog):
f = open("transcript.txt", "w") f = open("transcript.txt", "w")
f.write(transcript) f.write(transcript)
f.close() f.close()
last_message: discord.Message = await ctx.channel.fetch_message(ctx.channel.last_message_id)
#rename the file with the name of the channel and the date in this format: transcript_servername_channelname_dd-month-yyyy.txt ex : transcript_Botator_Testing_12-may-2021.txt
os.rename("transcript.txt", f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt")
#send the file in a private message to the user who ran the command #send the file in a private message to the user who ran the command
if channel_send is None: if channel_send is None:
await ctx.respond(file=discord.File("transcript.txt")) await ctx.respond(file=discord.File(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt"), ephemeral=True)
else: else:
await channel_send.send(file=discord.File("transcript.txt")) await channel_send.send(file=discord.File(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt"))
await ctx.respond("Transcript sent!", ephemeral=True) await ctx.respond("Transcript sent!", ephemeral=True, delete_after=5)
await ctx.author.send(file=discord.File("transcript.txt")) await ctx.author.send(file=discord.File(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt"))
#delete the file #delete the file
os.remove("transcript.txt") os.remove(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt")