【问题标题】:How to make discord bot only notify me when an user joining voice channel and already leaving voice channel more than 5 minutes before如何让不和谐机器人只在用户加入语音频道并且已经离开语音频道超过 5 分钟时通知我
【发布时间】:2021-11-24 03:11:34
【问题描述】:
@client.event
async def on_voice_state_update(member, before, after):
    # This function is called when not only member join to the voice channel,
    # but also member changed their status to mute.
    # So, it is necessary to catch only events that joining channel.
    if before.channel != after.channel:
        if after.channel is not None and after.channel.id == int(VOICE_CHANNEL_ID1):
            _name = member.nick if member.nick else member.name
            message = {
                "message": "\n" + _name + " Join The Livestream Channel"
            }
            requests.post(LINE_NOTIFY_API_URL, headers=HEADERS, data=message)
    if before.channel != after.channel:
        if after.channel is not None and after.channel.id == int(VOICE_CHANNEL_ID2):
            _name = member.nick if member.nick else member.name
            message = {
                "message": "\n" + _name + " Join The Nongskuy Channel"
            }
            requests.post(LINE_NOTIFY_API_URL, headers=HEADERS, data=message)

client.run(DISCORD_BOT_ACCESS_TOKEN)

所以我正在尝试制作一个机器人,当有人加入我的不和谐服务器中的语音频道时,它可以通知我的 LINE 组。问题是,我的朋友经常通过反复离开和加入语音频道来玩我的机器人,如果有人加入语音频道,我的机器人会在我的 LINE 组中发送垃圾邮件。所以,我需要帮助让我的机器人只通知我的 LINE 组如果用户已经离开语音频道 5 分钟并再次加入语音频道

【问题讨论】:

    标签: discord


    【解决方案1】:

    您似乎基本上想检查用户的每个语音频道离开/加入之间是否经过了 5 分钟或更多分钟。您可以使用datetime 模块获取用户加入和离开频道的时间。 How to get the current time in Python。获得时间后,您可以像这样获得时间的分钟数:

    >>> now = datetime.now()
    >>> print(now)
    2021-11-23 14:05:31.787939
    >>> print(now.minute)
    5
    

    因此您可以将now.minute 存储在另一个变量中,并在以后使用它进行比较。

    【讨论】:

      猜你喜欢
      • 2020-10-15
      • 2020-12-18
      • 1970-01-01
      • 2021-04-24
      • 2019-04-08
      • 2018-06-16
      • 1970-01-01
      • 2021-07-06
      • 2020-08-30
      相关资源
      最近更新 更多