删除命令消息 -Python -discord.py

时间:2021-07-18 22:35:52

标签: python discord discord.py

您好,我正在 discord.py 中编写一个机器人,我想知道是否有办法删除用户发送的命令消息,例如,用户使用命令 .help 并且机器人删除了留言 .help 并给出答案,你知道怎么做吗?

import os
import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix = '.', intents = intents)

@client.command(pass_context=True)
async def myCmd(message):
  #here the code to clear the message
  await message.send('Something') 

1 个答案:

答案 0 :(得分:1)

@client.command(pass_context=True)
async def myCmd(ctx):
  await ctx.message.delete()
  await ctx.send('Something') 

请注意,除非您要删除自己的消息,否则您需要 manage_messages 权限才能这样做。