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

使用discord.py 2.3.2实现成员入服DM功能失败求助

问题分析与解决

1. 核心问题:成员意图未启用(最常见原因)

discord.py 2.x版本默认关闭成员意图(Server Members Intent),这会导致on_member_join事件根本无法触发,自然不会执行发送私信的代码。

解决步骤:

  • Discord开发者后台配置:
    1. 登录Discord开发者平台,找到你的机器人应用;
    2. 进入Bot页面,滚动到Privileged Gateway Intents板块;
    3. 开启Server Members Intent开关。
  • 代码中启用意图:
    在初始化Bot时传入开启成员意图的配置:
    import discord
    from discord.ext import commands
    
    # 初始化意图,开启成员相关权限
    intents = discord.Intents.default()
    intents.members = True
    
    bot = commands.Bot(command_prefix="你的前缀", intents=intents)
    
    @bot.event
    async def on_member_join(member):
        try:
            await member.send(f"Welcome to .LDQ {member.mention}!")
        except discord.Forbidden:
            print(f"Failed to send a DM to {member.name} on join. (Forbidden: User blocked DM or privacy settings restrict it)")
        except Exception as e:
            print(f"Failed to send a DM to {member.name} on join. Error: {e}")
    
    bot.run("你的机器人Token")
    

2. 用户端隐私设置限制

测试小号的Discord隐私设置可能阻止了来自服务器成员/机器人的私信:

  • 让小号打开Discord设置 → 隐私与安全:
    • 确保允许来自服务器成员的直接消息处于开启状态;
  • 右键目标服务器 → 服务器设置 → 隐私设置:
    • 确认允许服务器成员向我发送直接消息未被关闭。

3. 其他排查方向

  • 检查测试小号是否拉黑了机器人账号;
  • 确认机器人账号正常在线,无Token失效或网络异常问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 23:47:13