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

Discord Bot无法检测语音频道用户问题求助

问题诊断与解决方案

核心问题

你的Discord Bot无法检测语音频道用户,根源是Intents权限配置不全,同时代码缺少日志输出逻辑,导致无法看到执行结果。

具体修复步骤

  • 补充必要的Intents权限
    你当前仅启用了voice_states和reactions,但要获取频道成员列表,必须开启members和guilds权限。不要用Intents.none()关闭所有默认权限,改用default()作为基础再补充所需权限:

    intents = discord.Intents.default()
    intents.voice_states = True
    intents.members = True  # 关键:获取成员列表必须开启此权限
    intents.guilds = True   # 确保正常访问服务器信息
    
  • 在Discord开发者后台开启特权意图
    仅代码配置不够,需登录Discord开发者后台,找到你的Bot应用,进入「Privileged Gateway Intents」页面,开启Server Members Intent和Voice States Intent,保存后重启Bot。

  • 添加日志输出逻辑
    原代码只生成了成员列表但未输出,添加打印代码才能看到结果,同时优化服务器获取逻辑避免索引报错:

    @client.event
    async def on_ready():
        print(f'Bot已登录:{client.user}')
        # 遍历所有服务器,避免单索引可能的报错
        for guild in client.guilds:
            print(f'\n当前服务器:{guild.name}')
            members = [member for channel in guild.voice_channels for member in channel.members]
            if members:
                print(f'语音频道在线用户:{[m.name for m in members]}')
            else:
                print('语音频道无在线用户')
    

完整修复代码示例

import discord

# 配置Intents
intents = discord.Intents.default()
intents.voice_states = True
intents.members = True
intents.guilds = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f'Bot已成功登录:{client.user}')
    for guild in client.guilds:
        print(f'\n=== 服务器:{guild.name} ===')
        for channel in guild.voice_channels:
            if channel.members:
                print(f'频道「{channel.name}」用户:')
                for member in channel.members:
                    print(f'- {member.name}')
            else:
                print(f'频道「{channel.name}」无在线用户')

# 替换为你的Bot Token
client.run('YOUR_BOT_TOKEN')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 15:10:37