added redo command (not working yet)

This commit is contained in:
Paillat
2022-12-16 12:51:46 +01:00
parent dc267b217c
commit 8772b4a293

View File

@@ -21,6 +21,31 @@ class Chat (discord.Cog) :
debug(f"The user {ctx.author.display_name} ran the say command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") debug(f"The user {ctx.author.display_name} ran the say command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}")
await ctx.respond("Message sent !", ephemeral=True) await ctx.respond("Message sent !", ephemeral=True)
await ctx.send(message) await ctx.send(message)
@discord.slash_command(name="redo", description="Redo a message")
async def redo(self, ctx: discord.ApplicationContext):
#first delete the last message but only if it was sent by the bot
# get the last message
last_message = await ctx.channel.fetch_message(ctx.channel.last_message_id)
# check if the last message was sent by the bot
# if it was, delete it
if last_message.author.id == self.bot.user.id:
await last_message.delete()
else:
await ctx.respond("The last message wasn't sent by the bot", ephemeral=True)
return
await ctx.defer()
#get the message to redo aka the last message, because the old last message has been deleted
#sleep for 1 second to make sure the message has been deleted
await asyncio.sleep(4)
last_message = await ctx.channel.fetch_message(ctx.channel.last_message_id)
#check if the message to redo was sent by the bot
if last_message.author.id == self.bot.user.id:
await ctx.respond("The message to redo was sent by the bot", ephemeral=True)
return
loop = asyncio.get_event_loop()
thread = threading.Thread(target=asyncio.run_coroutine_threadsafe, args=(on_message_process(last_message, self), loop))
thread.start()
await ctx.respond("Message redone !", ephemeral=True)
async def on_message_process(message, self): async def on_message_process(message, self):
#my code #my code
#debug the thread id #debug the thread id