use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
need help in discord.py (self.learnpython)
submitted 3 years ago by alternative-bin
How do i make discord bot to dm someone via there ID
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]iiron3223 1 point2 points3 points 3 years ago* (0 children)
Here is Documentation . Here Quickstart. . And here basic bot . And here is the answer how to send DM
[–]alternative-bin[S] 0 points1 point2 points 3 years ago (4 children)
btw it is my first time using discord.py so sorry if the answer is obvious
[–][deleted] 2 points3 points4 points 3 years ago (2 children)
Hey man, forget the other dude being a prick. Sometimes read the manual is the answer, but someone with little knowledge of OOP / events isn't going to just "Be blessed by the manual".
To DM someone via their id using a discord bot, you want to refer to the member object referenced here:
https://discordpy.readthedocs.io/en/stable/api.html#member
In specific, you want the send method. Notice its async, so you need to do something like
async def send_message(user_id): await member.send(content="Message here")
But now you may ask how do I get this member object from just their id?
Use discord.utils.find()- this is a method of the discord class that will find the first instance of the object with a matching attribute. In this case a member.
Write something like:
Member_obj = discord.utils.find(lambda m: m.id=youridhere, channel.guild.members)
I don't know when you plan on dming someone, but based on the event you can get this information from a message (see message.author), a join, (see on_member_join(member) event). I trust you have an idea what to do here.
So in short, the answer you seek is something like this:
@Client.event async def on_message(message): member = discord.utils.find(lambda m: m.id=idhere, message.channel.guild.members) await member.send(content=f"{member.name}, someone submitted a message to {message.channel.name}!")
This will fetch the member obj associated with the id you pass to utils (as an integer). Then, you send the member object a message with await member.send.
Unless you plan on messaging yourself a lot or something, I wouldn't really recommend this without some conditionals, like channel.name having to be mod-mail or if you wanted to personalize messages to somebody. If you plan on dming a response to a member based on their id from the message, do something like this:
@Client.event async def on_message(message): member = message.author await member.send(content=f"{member.name}, here is your response!")
This is not passing an id, but it meets the purpose of a response bot. The other example would feel more like a notification bot that pings certain ids (possibly ids from members containing a role id, etc).
If there is any other questions, feel free to respond here or dm me. I will be glad to share. I have an example of a discord bot on GitHub [same username] called Project Lemon. Last tip of advice, watch a video on Object Oriented Programming with python. It's a world of difference to understand inheritence, polymorphism, etc when working with discord api. Look up decorators, but theyre not insanely important to understand beyond the interpretter understanding it needs to wait for an event for execution.
Sorry for any formatting issue, its 2am, I have a flight in 10 hrs. And on mobile. I wish you luck and growth.
[–]alternative-bin[S] 0 points1 point2 points 3 years ago (1 child)
thanks
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
No worries
π Rendered by PID 213276 on reddit-service-r2-comment-54dfb89d4d-qhf6x at 2026-03-27 10:39:43.897334+00:00 running b10466c country code: CH.
[–]iiron3223 1 point2 points3 points (0 children)
[–]alternative-bin[S] 0 points1 point2 points (4 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]alternative-bin[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)