如何让机器人在一段时间后删除其嵌入消息



下午好,我想让机器人在一分钟内删除它的嵌入消息,我该如何实现它,这是代码

@client.command(pass_context = True)
@commands.has_any_role(819292703589269514,817408828500213860,817408830240456754,817643991331766283)
async def clear (ctx, amount : int):
await ctx.channel.purge(limit = amount + 1)
emb = discord.Embed (title = 'Удалено {} сообщений!'.format(amount), colour = discord.Color.gold())
await ctx.send(embed = emb)
await asyncio.sleep(15)
await emb.delete()

如果其他人有问题,这里有一个答案:

请注意正确的缩进,有些地方空格太多。

您也可以使用CCD_;事件";而不是您的CCD_ 2。

看起来是这样的:

@client.command(pass_context=True)
@commands.has_any_role(819292703589269514, 817408828500213860, 817408830240456754, 817643991331766283)
async def clear(ctx, amount: int):
await ctx.channel.purge(limit=amount + 1)
emb = discord.Embed(title='Удалено {} сообщений!'.format(amount), color=discord.Color.gold())
await ctx.send(embed=emb, delete_after=60) # delet_after added

如果你想使用你的方法,你必须定义你要发送的嵌入:

@client.command(pass_context=True)
@commands.has_any_role(819292703589269514, 817408828500213860, 817408830240456754, 817643991331766283)
async def clear(ctx, amount: int):
await ctx.channel.purge(limit=amount + 1)
emb = discord.Embed(title='Удалено {} сообщений!'.format(amount), colour=discord.Color.gold())
test1 = await ctx.send(embed=emb) # We define the embed as test1
await asyncio.sleep(15)
await test1.delete() # test1 (Embed) gets deleted

这很简单。您只需要定义一个发送嵌入的变量。这是代码-

@client.command(pass_context = True)
@commands.has_any_role(819292703589269514,817408828500213860,817408830240456754,817643991331766283)
async def clear (ctx, amount : int):
await ctx.channel.purge(limit = amount + 1)
emb = discord.Embed (title = 'Удалено {} сообщений!'.format(amount), colour = discord.Color.gold())
sendemb = await ctx.send(embed = emb)
await asyncio.sleep(15)
await sendemb.delete()

所以在这里,我所做的只是命名嵌入发送(sendemb(,在睡眠15秒后,它将其删除!

希望我帮了你。

最新更新