我如何才能知道某人当前是否正在 discord.py 中讲话?
How can i find out if a person is currently talking in discord.py?
我想知道有人在说话还是挂机了。
我找到了一些可能有用的例子,但我不太清楚它是否应该起作用。喜欢这个:
async def on_member(member):
if member.voice:
print("HI")
而且我想知道我是否必须导入其他东西,因为目前我只有:
import discord
from discord.ext import commands
您提供的示例 returns 一个 VoiceState
,您可能会使用它。如果你的公会设置了挂机语音通道和一键通语音通道,你可以这样做:
(阅读有关 on_voice_state_update()
here)
@bot.event
async def on_voice_state_update(member, prev, cur):
user = f"{member.name}#{member.discriminator}"
if cur.afk and not prev.afk:
print(f"{user} went AFK!")
elif prev.afk and not cur.afk:
print(f"{user} is no longer AFK!")
elif cur.self_mute and not prev.self_mute: # Would work in a push to talk channel
print(f"{user} stopped talking!")
elif prev.self_mute and not cur.self_mute: # As would this one
print(f"{user} started talking!")
澄清:
,除非您计划使用来自套接字的字节,但这是一个相当大的项目。
我想知道有人在说话还是挂机了。 我找到了一些可能有用的例子,但我不太清楚它是否应该起作用。喜欢这个:
async def on_member(member):
if member.voice:
print("HI")
而且我想知道我是否必须导入其他东西,因为目前我只有:
import discord
from discord.ext import commands
您提供的示例 returns 一个 VoiceState
,您可能会使用它。如果你的公会设置了挂机语音通道和一键通语音通道,你可以这样做:
(阅读有关 on_voice_state_update()
here)
@bot.event
async def on_voice_state_update(member, prev, cur):
user = f"{member.name}#{member.discriminator}"
if cur.afk and not prev.afk:
print(f"{user} went AFK!")
elif prev.afk and not cur.afk:
print(f"{user} is no longer AFK!")
elif cur.self_mute and not prev.self_mute: # Would work in a push to talk channel
print(f"{user} stopped talking!")
elif prev.self_mute and not cur.self_mute: # As would this one
print(f"{user} started talking!")