2
votes
import discord
import asyncio
client = discord.Client()

@client.event
async def on_ready():
    print ("I’m Now Online")

@client.event
async def on_message(message):
  if message.author == client.user:
    return
  elif message.content.startswith("deletethis"):

I’m wonder how I could be able to add to this to delete the above command when the author of the message sends the command above. May someone help create one? I’ve tried my self by brain and didn’t find anything online so I’m looking for some help maybe.

1
Use Client.delete_message: await client.delete_message(message) - Patrick Haugh

1 Answers

3
votes

for async just do

await client.delete_message(message)

otherwise for rewrite just do

await message.delete()

Finished code:

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith("deletethis"):
      await asyncio.sleep(1)
      await message.delete()