Discord Bot Python执行后删除用户消息

时间:2020-10-27 11:34:06

标签: python discord.py discord.py-rewrite

有人可以帮我吗,我只想删除作者发送来执行命令的消息

@bot.command(description="Displays the test on_member_join message", aliases=['tw'], pass_context=True)
@commands.has_permissions(administrator=True)
async def test_welcome(ctx):
    user = ctx.author
    if user.bot:
        pass
    else:
        now = datetime.now()
        dt_string = now.strftime("on %d/%m/%Y at %H:%M")
        embed = discord.Embed(description=f"{user.display_name} **Joined The Server**", colour=0x73D673)
        embed.set_author(name=user.display_name, icon_url=user.avatar_url)
        embed.set_thumbnail(url=thumbnail)
        embed.add_field(name="User ID:", value=user.id)
        embed.set_footer(text=dt_string)
        #how to make it delete the message the user sent to excute this command
        await ctx.send(embed=embed, delete_after=1)

2 个答案:

答案 0 :(得分:1)

如果要删除命令执行消息,例如prefix test_welcome,则可以使用await ctx.message.delete()

答案 1 :(得分:0)

无论哪种方式,您都可以使用await ctx.message.delete。我建议您阅读documentation