Discord.py bot 不会 dm 新成员

时间:2021-01-26 20:02:56

标签: python discord discord.py discord.py-rewrite

我正在使用 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)

1 个答案:

答案 0 :(得分:2)

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

为了让机器人找到成员,您需要在您的机器人中开启成员意图。你可以使用下面的图片来做到这一点。

enter image description here

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

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