Python 机器人不';我不想显示频道的id

Python 机器人不';我不想显示频道的id,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,我希望bot打印成员连接到的频道的id @client.event async def on_voice_state_update(member, before, after): channelid = discord.VoiceChannel.id print(f'{channelid}') 当我加入这个频道时,我得到了: <member 'id' of 'VoiceChannel' objects> 因为您正在尝试获取VoiceChannelid,而Voic

我希望bot打印成员连接到的频道的id

@client.event
async def on_voice_state_update(member, before, after):
    channelid = discord.VoiceChannel.id
    print(f'{channelid}')
当我加入这个频道时,我得到了:

<member 'id' of 'VoiceChannel' objects>


因为您正在尝试获取
VoiceChannel
id,而
VoiceChannel
是一个类,而不是实际的频道。要获取语音频道的id,可以使用.channel.id之前的
或.channel.id之后的
。这取决于你想做什么。因此,您可以按如下方式更改代码:

@client.event
语音状态更新时的异步定义(成员、之前、之后):
channelid=在.channel.id之前
打印(f'{channelid}')
据我所知,如果成员加入语音频道,则
在.channel.id之前
返回
,如果成员离开语音频道,则
在.channel.id之后
返回