Discord.py |让机器人找出它发送的嵌入并将其全部删除?

2024-09-29 22:45:08 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有任何方法可以发出像>delembeds这样的命令,或者让bot查找它发送的所有嵌入并删除它们?谢谢你的帮助


Tags: 方法命令botdelembeds
1条回答
网友
1楼 · 发布于 2024-09-29 22:45:08

您可以使用discord.TextChannel.history获取消息,然后检查它是否包含嵌入。如果需要,可以将限制更改为None,但速度会很慢。请记住,无论是否嵌入,通道中每条消息的限制都会计数

这将删除频道中的所有嵌入内容,而不考虑作者

@bot.command()
async def delembeds(ctx):
    messages_in_channel = await ctx.channel.history(limit=30).flatten()
    for message in messages_in_channel:
        if message.embeds:  # if it has an embed
            await message.delete()

    await ctx.message.add_reaction("✅")

相关问题 更多 >

    热门问题