When awaiting a pin with on_guild_channel_pins_update
, both pin and unpin actions are detected. I am looking to get the message ID of a message the second it is pinned. 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. 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.
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.
@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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.