Sending another embed after deleting embed not working

Solution 1:

await ctx.send(embed=embed, delete_after=5) use asyncio.sleep function to wait before deleting the message.

You use blocking call: time.sleep(5). It blocks all your code and also blocks await ctx.send(embed=embed, delete_after=5) timer execution.

You should use asyncio.sleep:

import asyncio


@client.command()
async def test(ctx):
  with open('test.json', 'r') as homeworkfile:
    homework = json.loads(homeworkfile.read())
  embed=discord.Embed(title='Test', description=f"Here's the saved contents for test: {homework}", color=0x9932CC)
  deletewarn=discord.Embed(title='Answer ticket expired.', description="Oops, looks like this ticket expired. Try saying !ss again?", color=0x9932CC)
  await ctx.send(embed=embed, delete_after=5)
  await asyncio.sleep(5)
  await ctx.send(embed=deletewarn)

Solution 2:

Change time.sleep(5) to await asyncio.sleep(5) instead. While using time.sleep your entire code is frozen.

Your code works like this:

  1. Sends your first message
  2. Immediately "sleeps" for 5 seconds (because of time.sleep(5))
  3. After 5 seconds code resumes:
    • sends your second message
    • starts 5 second counter you used in delete_after=5

That's why it waits 10 seconds before deleting the message instead of the 5 you wanted. It just starts counter execution for delete_after=5 later, because your time.sleep froze the whole code.


Remember to import asyncio to use asyncio.sleep.