You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Nextcord机器人无法检测用户实际加入语音频道的问题?

问题解决

你的代码里硬编码了语音频道为"Lobby",所以无论用户加入哪个语音频道,都会固定显示这个频道。只需要直接使用after.channel就能获取用户实际加入的语音频道,不需要再通过nextcord.utils.get去查找固定名称的频道。

修正后的代码如下:

@client.event
async def on_voice_state_update(member, before, after):
    if not before.channel and after.channel:
        # 获取发送通知的文字频道
        text_channel = nextcord.utils.get(member.guild.channels, name="general")
        # 直接使用after.channel获取用户加入的语音频道
        await text_channel.send(f'I noticed that {member.mention} just joined {after.channel.mention}!')

说明

  • after.channel是on_voice_state_update事件提供的参数,代表用户状态更新后所在的语音频道,当用户刚加入语音频道时,这个值就是他们实际进入的频道。
  • 原来的代码通过nextcord.utils.get固定查找名为"Lobby"的频道,这就是导致显示固定频道的原因,替换成after.channel即可解决问题。

内容的提问来源于stack exchange,提问作者Kkoko Koko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 21:53:12