Discord.py:如何浏览频道历史并搜索特定消息?

时间:2020-09-12 18:57:28

标签: discord.py

本质上,我希望该漫游器浏览该频道的消息历史记录,查找包含某些特定文本的消息,然后在同一频道中给出指向该消息的链接。

在阅读文档时,我想我会使用async for message in channel.history(params),但是我无法弄清楚特定用例的用法。

1 个答案:

答案 0 :(得分:1)

您处在正确的轨道上,可以使用channel.history来获取消息。然后,只需将您的关键字与邮件内容进行比较,然后使用jump_url获取该邮件的链接。

@client.command()
async def keyword(ctx, *, word: str):
    channel = client.get_channel(730839966472601622)
    messages = await ctx.channel.history(limit=200).flatten()

    for msg in messages:
        if word in msg.content:
            print(msg.jump_url)