Reputation: 13
@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
Upvotes: -1
Views: 1954
Reputation: 370
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")
Upvotes: -1
Reputation: 2917
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")
Upvotes: -2