Command message Delete Discord Py code example

Example 1: delete message discord.py

@client.event
async def on_message(message):
    await message.delete()

Example 2: discord.py delete own message

#this code will send "HI" for 3 seconds when the user says "HI"
#discord.py rewrite
#python 3+
include time
@bot.event
async def on_message(message):
  #Only continue if the message is "HI"
  if not message.content == "HI":
    return
  #Send HI back, and set it to a var
  BotMessage = await ctx.send("HI")
  #wait 3 seconds
  time.sleep(3)
  #delete the bot's msg
  BotMessage.delete()

Tags:

Misc Example