我正在制作一个不协调的机器人来跟踪在语音通道上花费的时间,但是我想知道如何做到这一点不计算在某个通道(例如afk通道)上的成员的时间。
这是我现在正在使用的事件
@client.event
async def on_voice_state_update(before, after):
"""Monitor status updates for voice channels"""
s = session()
# prefer nickname in server to actual discord username
member_name = before.nick if before.nick else before.name
try:
member = s.query(Member).filter(Member.id == before.id).one()
# update member names on each channel join
member.name = member_name
except NoResultFound:
member = Member(
id=before.id,
name=member_name,
last_join=datetime.datetime.now(),
total_time=datetime.timedelta(0),
in_chat=False
)
s.add(member)
if after.voice.voice_channel is None:
if member.in_chat:
member.in_chat = False
member.update_total_time()
try:
channel_name = before.voice.voice_channel.name
except AttributeError:
channel_name = "Unknown"
print("{} left voice channel {}. Total time: {}".format(
member.name,
channel_name,
member.total_time
))
else:
if member.in_chat:
if after.voice.is_afk or after.voice.self_deaf or after.voice.deaf:
member.in_chat = False
member.update_total_time()
else:
member.in_chat = True
member.last_join = datetime.datetime.now()
try:
channel_name = after.voice.voice_channel.name
except AttributeError:
channel_name = "Private"
print("{} joined voice channel {}. Total time: {}".format(
member.name,
channel_name,
member.total_time
))
s.commit()
sys.stdout.flush()
答案 0 :(得分:0)
如果我正确理解了您的代码,您将能够检查他们刚刚加入的语音通道是否具有特定的ID,应该是AFK通道的ID:
ic_stat_onesignal_default
如果要针对多个ID检查ID,可以将其与列表进行比较:
flutter run --release
参考: