วิธีที่จะทำให้ discord bot เดียวที่แจ้งให้ทราบฉันตอนที่เป็นของผู้ใช้ร่วมกันอเสียงของช่องและไปจากเสียงช่องมากกว่า 5 นาทีก่อน

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)

ดังนั้นฉันกำลังพยายามทำ bot ที่สามารถแจ้งให้ทราบของเส้นกลุ่มเมื่อไรก็ตามที่มีคนเข้าร่วมกันเสียงช่องในของฉัน discord เซิร์ฟเวอร์ ปัญหาคือเพื่อนฉันบ่อยแค่เล่นกับของฉัน bot เดินออกไปและเข้าร่วมกับเสียงของช่อง repeatly และของฉัน bot จะ spamming อยู่ในเส้นกลุ่มถ้าใครซักคนเข้าร่วมกับเสียงของช่องดังนั้นฉันต้องการช่วยเพื่อทำให้ฉัน bot เดียวที่แจ้งให้ทราบของเส้นกลุ่มถ้าเป็นของผู้ใช้แล้วทิ้งเสียงช่องสำหรับ 5 นาทีและเข้าร่วมกันอีกครั้ต้องเสียงช่อง

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

คำตอบที่ดีที่สุด

0

มันดูเหมือนว่าคุณโดยพื้นฐานอยากจะตรวจสอบว่า 5 หรืออีกนาทีได้ผ่านระหว่างซึ่งกันและเสียงช่องปล่อ/เข้าร่วมของคนใช้งาน คุณสามารถใช้ datetime ศูนย์ควบคุม kde ในโมดูลที่จะให้เวลาเมื่อผู้ใช้งานร่วมและออกจากช่อง วิธีที่จะเอาเวลาปัจจุบันภาษาไพธอน. เมื่อคุณไปถึงเวลา,คุณสามารถพานาทีของเวลาแบบนี้:

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

ดังนั้นคุณสามารถร้าน now.minute อยู่ในตัวแปรอื่นแล้วใช้มันเพื่อทำการเปรียบเทียบในภายหลัง

2021-11-23 19:11:34

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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