Skip to content

Conversation

@DancingSnow0517
Copy link
Contributor

@DancingSnow0517 DancingSnow0517 commented Nov 13, 2023

一个更加实用的方法来注册事件

# 使用 event 装饰器将 async 方法作为 event_handle
@bot.event
async def on_btn_click(event: TypedEvent.UserEvent.MessageButtonClickEvent):  # 使用方法第一个参数的 typehint 来获取注册的事件类型
    # 可以更加简便的获取事件相关内容,而不是从 body 字典里找
    print(event.value)
    print(event.msg_id)
    print(event.target_id)


#与上面同理
@bot.event
async def on_joined_guild(event: TypedEvent.GuildUserEvent.JoinedGuildEvent):
    print(event.user_id)
    print(event.joined_at)


#与上面同理
@bot.event
async def on_pin_message(event: TypedEvent.ChannelEvent.PinnedMessageEvent):
    print(event.msg_id)
    print(event.operator_id)

@TWT233 TWT233 added the need review new / changed label Jan 18, 2024
@TWT233 TWT233 self-assigned this Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need review new / changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants