python - 如何在 discord.py 中将用户的离开和加入时间记录到语音频道?
问题描述
嘿伙计们,我正在编写一个不和谐的机器人,我想在用户进入和离开语音频道时进行记录。但显然,我现在有点困惑。你们对我如何使用有任何想法on_voice_state_update()
吗?
解决方案
请看这里。
它接受两个参数before
and after
,因此要检查是否有人离开,只需比较before
and after
,如果不一样,您可以将其记录在某个文件中(也许json
or pickle
orsqlite
库可以帮助解决这个问题)
我在下面提供了一些快速示例代码:
@client.event
async def on_voice_state_update(member, before, after):
if before.channel is None and after.channel is not None:
print("difference")
我们观察一些事情:首先,before
andafter
是对象,你可以在这里VoiceState
查看它们的属性,这就是我得到的等等。before.channel
其次,client
是你命名你的机器人的任何东西(即client = commands.Bot(..)
)
推荐阅读
- python - 比较kNN中的多个数组
- javascript - 如何从具有云功能的嵌套引用中获取通配符
- angular - Angular 6:将数据传递到 FireBase 集合时出错
- function - 函数中的 Haskell getLine 否则
- linux - 使用 DramSim2 运行 gem5
- google-analytics - 谷歌标签管理器在单页应用程序中重新创建相同的标签
- c++ - c++ 主题名称到字符串向量的映射
- read-eval-print-loop - Chez计划的先前结果
- php - Laravel Auth 注册路径或登录路径未找到
- bash - How do I compare time in bash?