简体   繁体   English

等待 discord.py 中的用户引脚?

[英]await user pins in discord.py?

When awaiting a pin with on_guild_channel_pins_update , both pin and unpin actions are detected.当使用on_guild_channel_pins_update等待 pin 时,会检测 pin 和 unpin 操作。 I am looking to get the message ID of a message the second it is pinned.我希望在固定消息的第二个消息中获取消息 ID。 However, this method's only parameters are channel , returning the channel where the pin action was detected, and last_pin , which returns only a UTC timestamp of the most recently pinned message in channel , regardless of the message that triggered the function in the first place.但是,此方法的唯一参数是channel ,返回检测到 pin 操作的通道和last_pin ,它仅返回channel中最近固定消息的 UTC 时间戳,而不管首先触发 function 的消息。 If this function did not include unpin actions, I could simply use await channel.pins() to get a list of all the pins in the channel and use the message ID of whatever is at index 0, but because this function triggers even when a pin is removed, this creates several cases where the bot would return something that has been pinned for months.如果这个 function 不包括取消固定操作,我可以简单地使用await channel.pins()来获取通道中所有引脚的列表并使用索引 0 处的任何消息 ID,但是因为这个 function 即使在pin 被删除,这会产生几种情况,其中机器人将返回已固定数月的内容。

Any help would be appreciated.任何帮助,将不胜感激。

You can do this using on_message_edit() , which triggers whenever something happens to a message, which includes being pinned.您可以使用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