Discord.py: How to send a private message.

Created on 17 Jan 2018  路  5Comments  路  Source: Rapptz/discord.py

I saw where someone else asked this question but when I tried using it in that context I couldn't get it to work maybe you can show me an example line?

question

Most helpful comment

This looks like you're trying to ask how to DM a user based on an ID. Your image already shows how to do this, so you can just combine it with the documentation as shown by @Dalekfodder :

user = discord.utils.get(client.get_all_members(), id='1234')

if user is not None:
    await client.send_message(user, "A message for you")
else:
    # Your bot can't see the user, and therefore wouldn't have permission to DM them anyway.
    # Choose how you want to handle this here.

All 5 comments

A quick search on the documents gives you this:
https://gyazo.com/09c06af18538031b1f8c85cb87bc81bf

Now imagine what you can do with a slightly longer search.

Yeah thanks... But I have already seen that as well as the other line that is given.
https://imgur.com/a/nTOoE
I am looking for an example of the line involving the id of the user.
When I have tried using it how it was shown above I receive errors based on the input given.
So what better way to see how it's done than to get another example line?
If I am wrong in my explanation just let me know.

This looks like you're trying to ask how to DM a user based on an ID. Your image already shows how to do this, so you can just combine it with the documentation as shown by @Dalekfodder :

user = discord.utils.get(client.get_all_members(), id='1234')

if user is not None:
    await client.send_message(user, "A message for you")
else:
    # Your bot can't see the user, and therefore wouldn't have permission to DM them anyway.
    # Choose how you want to handle this here.

But instead of having a fixed ID how would I put a imput so I could do
!dm 123456789 test

Kindly do not post on dead, long gone closed issues.

The README links a help server that you can join to request help with library use. GitHub issues are not where help is given.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SakiiR picture SakiiR  路  17Comments

pappabewar picture pappabewar  路  26Comments

AceKiron picture AceKiron  路  23Comments

rektile picture rektile  路  18Comments

imayhaveborkedit picture imayhaveborkedit  路  58Comments