On message delete message Discord.py

我是研究僧i 提交于 2021-01-04 06:23:33

问题


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:


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()


来源:https://stackoverflow.com/questions/48351265/on-message-delete-message-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!