首页 > 解决方案 > Discord.py 机器人不会 dm 新成员

问题描述

我正在使用事件 on_member_join 来尝试 dm 新成员,但是当我使用我的 alt 进行测试时,它没有发送消息。

@bot.event
async def on_member_join(member):
  embed = discord.Embed(title="Welcome to my server!", description=None, color = discord.Color.magenta())
  embed.add_field(name="To get started:", value="•Invite some friends!\n•Check out some of the channels and get engaged with the community!\n•Have fun!", inline=True)
  channel = bot.get_channel(803703488499810326)
  userDM = member.create_dm()
  await userDM.send(embed=embed)

标签: pythondiscorddiscord.pydiscord.py-rewrite

解决方案


您不需要这样做,member.create_dm()因为当您 DM 用户时不需要这样做。您也不需要定义description为 None,您甚至不需要指定描述。

为了让机器人甚至可以找到成员,您需要在机器人中打开成员意图。您可以使用下图来做到这一点。

在此处输入图像描述

现在,您只需要在机器人中提供代码,以便机器人可以使用意图。这是您需要添加到主机器人文件的代码。

intents = discord.Intents.default() # Gets the default intents from discord.
intents.members = True # enables members intents on the bot.

bot = commands.Bot(command_prefix=prefix, intents=intents)

毕竟这里是你的固定代码。

@bot.event
async def on_member_join(member):
  embed = discord.Embed(title="Welcome to my server!", description=None, color = discord.Color.magenta())
  embed.add_field(name="To get started:", value="•Invite some friends!\n•Check out some of the channels and get engaged with the community!\n•Have fun!", inline=True)
  await member.send(embed=embed)

我希望这会有所帮助,祝你有美好的一天,祝你的机器人好运。这是面向初学者的 Discord 服务器。

Discord.py 初学者https ://discord.gg/C8zFM3D2rn


推荐阅读