如何让机器人在5秒钟后删除自己的消息 [英] How to make a bot delete its own message after 5 seconds

查看:149
本文介绍了如何让机器人在5秒钟后删除自己的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让漫游器删除自己的消息.

I can't get the bot to delete its own message.

我已经尝试等待 ctx.message.delete() ctx.message.delete(embed)

@bot.command()
async def help(ctx):
    embed=discord.Embed(title="List of commands.", description="", colour=discord.Color.orange(), url="")
    await ctx.send(embed=embed)
    await ctx.message.delete()
    await asyncio.sleep(5)
    await message.delete()

我要让漫游器删除命令,然后发送嵌入代码:命令列表已发送到您的DM's,然后等待5秒钟并删除嵌入代码

I'm wanting the bot to delete the command then send an embed: "A list of commands has been sent to your DM's" then wait 5 secs and delete the embed

推荐答案

ctx.message.delete()从用户删除消息.

ctx.message.delete() deletes the message from the user.

但是要删除漫游器的消息,您需要漫游器的消息对象
来自 ctx.send() return :

But to delete the bot's message you need the bot's message object
from the return of ctx.send() :

bot.remove_command('help') # Removes default help command 

@bot.command()
async def help(ctx):
    embed=discord.Embed(title="List of commands.", description="", colour=discord.Color.orange())
    msg = await ctx.send(embed=embed) # Get bot's message

    await ctx.message.delete() # Delete user's message
    await asyncio.sleep(5)

    await msg.delete() # Delete bot's message


编辑:您可以使用参数 delete_after = (float)


EDIT: You can use parameter delete_after=(float)

await ctx.send(embed=embed, delete_after=5.0)

这篇关于如何让机器人在5秒钟后删除自己的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆