-1
@client.event
async def on_message(message):
     if message.content == "help me":
         user = client.get(My_id) 
         if user is not None:
             await user.send("Someone needs help")

Is there any way to make bot dm me when someone sends a specific text like they type help me in channel and I get dm that "Hi someone needs help" I tried the code above but didnt work it shows user = client.get(My_id) AttributeError: 'Bot' object has no attribute 'get' please give the answer in python and Thanks in advance for the answer and I I'm making the bot for discord

Jack0845
  • 13
  • 4

2 Answers2

-1

try it:

@client.event
async def on_message(message):
     if message.content == "help me":
         user = await client.fetch_user(12345678909876543) # id goes here

         if user is not None: # if id is correct
             if user.dm_channel is None: 
                 # if DM channel is not created
                 await user.create_dm()

             await user.dm_channel.send("Someone needs help")
Delta
  • 362
  • 1
  • 8
  • File "main.py", line 151, in on_message if user.dm_channel is None: AttributeError: 'coroutine' object has no attribute 'dm_channel' /opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py:319: RuntimeWarning: coroutine 'Client.fetch_user' was never awaited pass RuntimeWarning: Enable tracemalloc to get the object allocation traceback. shows this error – Jack0845 Jan 22 '22 at 16:07
-2

You can do it using discord.py library for python. Just create simple event listener and send DM to a user with given ID like this:

import discord

intents = discord.Intents.default()
intents.members = True

client = discord.Client()

@client.event
async def on_message(message):
    if message.content == "help me":
        user = client.get(YOUR_ID)  # specify your Discord account ID here
        if user is not None:
            await user.send("Hi someone needs help")

client.run("TOKEN")
Ratery
  • 2,863
  • 1
  • 5
  • 26