簡體   English   中英

等待 discord.py 中的用戶引腳?

[英]await user pins in discord.py?

當使用on_guild_channel_pins_update等待 pin 時,會檢測 pin 和 unpin 操作。 我希望在固定消息的第二個消息中獲取消息 ID。 但是,此方法的唯一參數是channel ,返回檢測到 pin 操作的通道和last_pin ,它僅返回channel中最近固定消息的 UTC 時間戳,而不管首先觸發 function 的消息。 如果這個 function 不包括取消固定操作,我可以簡單地使用await channel.pins()來獲取通道中所有引腳的列表並使用索引 0 處的任何消息 ID,但是因為這個 function 即使在pin 被刪除,這會產生幾種情況,其中機器人將返回已固定數月的內容。

任何幫助,將不勝感激。

您可以使用on_message_edit()來執行此操作,它會在消息發生任何事情時觸發,包括被固定。

@client.event
async def on_message_edit(before, after):
    if not before.pinned and after.pinned:  # check if the action was a message being pinned
        print(after.id)                     # do whatever you want with the ID

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM