khl.py icon indicating copy to clipboard operation
khl.py copied to clipboard

Add event manager for khl.py

Open DancingSnow0517 opened this issue 1 year ago • 0 comments

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


# 使用 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)

DancingSnow0517 avatar Nov 13 '23 10:11 DancingSnow0517