How to make discord bot only notify me when an user joining voice channel and already leaving voice channel more than 5 minutes before

0

@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)

so i'm trying to make a bot that can notify my LINE group whenever someone joining voice channel in my discord server. The problem is, my friend often playing with my bot by leaving and joining the voice channel repeatly and my bot will spamming in my LINE group if someone joining the voice channel.So, i need a help to make my bot only notify my LINE group if an user is already leaving voice channel for 5 minutes and joining again to voice channel

discord
2021-11-23 15:55:57
1

0

It seems that you essentially want to check if 5, or more, minutes have passed between each voice channel leave/join of a user. You can use the datetime module to get the time of when a user joined and left the channel. How to get the current time in Python. Once you get the time, you can get the minutes of the time like this:

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

So you can just store now.minute in another variable and use it for comparison later on.

2021-11-23 19:11:34

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................