【问题标题】:Discord.py bot doesn't dm new membersDiscord.py 机器人不会 dm 新成员
【发布时间】:2021-04-30 15:43:46
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

您不需要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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-14
    • 2023-03-31
    • 2021-06-12
    • 2020-11-16
    • 2018-05-10
    • 2021-05-20
    • 1970-01-01
    • 2021-05-10
    相关资源
    最近更新 更多