检测是否有人被 Discord.py bot 服务器静音

时间:2021-04-23 10:28:09

标签: python discord discord.py

我需要机器人检测谁在服务器中被静音并将其输出到文本通道

import discord

intents = discord.Intents.all()
intents.voice_states = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
  print('logged as {0.user}'.format(client))

@client.event
async def on_voice_state_update(member, before, after):
  channel = discord.utils.get(member.guild.channels, name='sprava-serveru')
  print(before)
  print(after)

client.run([TOKEN])

on_voice_state_update 只返回 self_muteself_deaf 属性,而不是 mutedeaf em>。我认为意图会解决这个问题,但我不知道如何解决。我尝试了 discord.Intents.all()discord.Intents.default() 但没有任何效果。

print(before)print(after) 的输出:

<VoiceState self_mute=False self_deaf=False self_stream=False suppress=False requested_to_speak_at=None channel=<VoiceChannel id=834407963245936661 name='Senát' rtc_region=None position=3 bitrate=64000 user_limit=0 category_id=834407913190850610>>
<VoiceState self_mute=False self_deaf=False self_stream=False suppress=False requested_to_speak_at=None channel=<VoiceChannel id=834407963245936661 name='Senát' rtc_region=None position=3 bitrate=64000 user_limit=0 category_id=834407913190850610>>

谢谢

1 个答案:

答案 0 :(得分:0)

在打印 deaf 对象时看不到 muteVoiceState 属性没关系,如果您查看文档,它显然具有属性您正在寻找:VoiceState.deafVoiceState.mute