Sending a message to a specific user specified in the message, discord.py

橙三吉。 提交于 2021-01-07 04:26:31

问题


In my discord.py code I am trying to set up a simple send message to a user that the message author has specified.

    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)

The !hello command works fine, but I do not know how to get the User ID as an object for the send message command after receiving their ID as a string.


回答1:


Use discord.utils.get.

Assuming this is happening in a server, where both the command invoker and the target are: target = discord.utils.get(message.server.members, id=a)



来源:https://stackoverflow.com/questions/54081106/sending-a-message-to-a-specific-user-specified-in-the-message-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!