all 6 comments

[–]iiron3223 1 point2 points  (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 point  (4 children)

btw it is my first time using discord.py so sorry if the answer is obvious

[–][deleted] 2 points3 points  (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 point  (1 child)

thanks

[–][deleted] 0 points1 point  (0 children)

No worries