当有人使用某个命令时试图让机器人 DM 我

时间:2021-05-06 03:19:10

标签: python discord discord.py

当有人使用 shelp 命令时,我希望机器人自己 DM 说他们使用了该命令。我试图让它这样做,但是当我输入命令时,机器人没有 DM 我。我在启动或键入命令时没有收到任何错误。我怎样才能让我的机器人做到这一点?提前致谢!下面的代码是我目前得到的代码。

@bot.command()
async def shelp(ctx):
  embed=discord.Embed(title="Suici** Hotlines", description="US - 800-273-8255, Canada - 833-456-4566, Mexico - 55-5259-8121, Ireland - 116 123 OR text HELLO to 50808, Australia - 13 11 14 United Kingdom - 01708 765200. Remember that you are LOVED! You can do this, we believe in you! If you dont see your country above, please open a support ticket and we will find the # for you.", color=0x00FFFF)
  await ctx.send(embed=embed)

  user = bot.get_user('467715040087244800') #my discord id
  await bot.send_message(user, f"{ctx.author.name} used the shelp command in {ctx.guild.name}!")

2 个答案:

答案 0 :(得分:1)

bot.send_message 已折旧,请改用 user.send

await user.send(f"{ctx.author.name} used the shelp command in {ctx.guild.name}!")

答案 1 :(得分:1)

注意:使用this question作为参考

这将要求您拥有您想要联系的人的成员对象,在本例中为您。这可以通过您的 ID(通过开发者模式获取,可以在外观设置中切换)和 fetch_user 来完成,如下所示:

@bot.command()
async def dmcole(ctx):
    user_id = Your_Id
    user = await bot.fetch_user(user_id)
    channel = await user.create_dm()
    await channel.send("Hey!")