【问题标题】:Discord.py Leveling system - Points for minutes in voice channelsDiscord.py 调平系统 - 语音频道中的分钟数
【发布时间】:2021-11-25 22:31:37
【问题描述】:

我正在创建一个带有等级系统的 Discord Bot,您可以在其中获得消息积分。但我也想在语音频道中每分钟获得积分。我怎样才能知道用户何时加入以及他加入了多长时间?

【问题讨论】:

  • 也许使用on_voice_state_update事件

标签: python discord discord.py


【解决方案1】:

创建变量或数据文件并使用voice_state_state_update,当用户/机器人加入语音通道时调用。 (基本上发生语音相关变化时调用。包括静音、震耳欲聋等)

data = dict()
async def on_voice_state_update(member, before, after):
    if not before.channel and after.channel:
        data[member.id] = time.time()
    elif before.channel and not after.channel and member.id in data:
        minutes = (time.time() - data[member.id]) // 60
        add_points(minutes * <points_per_min>)

注意:这只是获取用户语音频道时间的基本逻辑,你必须做更多的检查和其他东西才能使它更好

【讨论】:

    猜你喜欢
    • 2021-07-28
    • 2018-04-04
    • 1970-01-01
    • 2021-01-07
    • 2020-07-13
    • 2021-06-06
    • 1970-01-01
    • 2020-09-07
    • 2021-06-05
    相关资源
    最近更新 更多