将消息发送给消息中指定的特定用户discord.py

时间:2019-01-07 20:11:09

标签: python discord discord.py

在我的discord.py代码中,我试图向消息作者指定的用户设置一条简单的发送消息。

    if message.content.startswith('!hello'):
  print("Hello DIRECT MESSAGE")
  msg = "Why hello there"
  print (message.author)
  await client.send_message(message.author, msg)

if message.content.startswith('!poke'):
  print("Poke DIRECT MESSAGE")
  a = message.content[6:]
  print(a)
  msg = "Hi there"
  await client.send_message(a, msg)

!hello命令可以正常工作,但在将用户ID作为字符串接收后,我不知道如何将用户ID作为发送消息命令的对象。

1 个答案:

答案 0 :(得分:0)

使用discord.utils.get

假设这是在服务器中发生的,其中命令调用者和目标都是: target = discord.utils.get(message.server.members, id=a)