0
votes

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

1 Answers

0
votes

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)