宁静获取客户端 ID
Serenity get client ID
当使用 Serenity 作为 discord 机器人时,如何在 EventHandler 中获取客户端的 id?
我不确定如何获取客户端及其 ID。我需要这个,以便我可以确保机器人正在响应的消息不是它自己的。另外,不,检查消息是否由机器人发送将不起作用,因为我需要这样做以便它也可以响应其他机器人的消息。如果有另一种方法无需在 EventHandler 中获取客户端的 ID,我也可以接受。静态变量不算。
给你的参数之一是 Context
value, and you can get the current user through its cache, from Cache::current_user_id()
:
// Assuming ctx is the name of the Context argument:
let my_uid = ctx.cache.current_user_id();
这需要 serenity
箱子的 cache
功能。
当使用 Serenity 作为 discord 机器人时,如何在 EventHandler 中获取客户端的 id?
我不确定如何获取客户端及其 ID。我需要这个,以便我可以确保机器人正在响应的消息不是它自己的。另外,不,检查消息是否由机器人发送将不起作用,因为我需要这样做以便它也可以响应其他机器人的消息。如果有另一种方法无需在 EventHandler 中获取客户端的 ID,我也可以接受。静态变量不算。
给你的参数之一是 Context
value, and you can get the current user through its cache, from Cache::current_user_id()
:
// Assuming ctx is the name of the Context argument:
let my_uid = ctx.cache.current_user_id();
这需要 serenity
箱子的 cache
功能。