【问题标题】:Get last sent attachment discord.py获取最后发送的附件 discord.py
【发布时间】:2023-01-09 03:28:53
【问题描述】:

我需要在频道中获取之前发送的附件以用作参数

我使用await ctx.get_channel(channel).history(limit=10).flatten()[0] 来获取以前发送的消息 我只是不知道如何获取最近发送的消息依恋从消息中

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    要从消息中获取最新的附件,您可以遍历消息列表并检查每条消息是否有任何附件。如果是,您可以获取附件并将​​其用作参数。

    以下是如何执行此操作的示例:

    messages = await ctx.get_channel(channel).history(limit=10).flatten()
    
    for message in messages:
        if message.attachments:
            attachment = message.attachments[0]
            # Use attachment as an argument here
    

    此代码将获取指定频道中最近的 10 条消息,然后循环遍历这些消息以找到第一条带附件的消息。然后它将从该消息中获取附件并将​​其用作参数。

    我希望这有帮助!如果您有任何问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 2018-01-15
      • 1970-01-01
      • 2022-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多