Matt
Matt

Reputation: 57

How do I trigger my bot to DM a user after an on_message event discord.py

I'm trying to make my bot message a user directly if they type a certain word, for example the letter 'E', but I can't figure out how to do this. Any help is appreciated!

Upvotes: 0

Views: 1392

Answers (3)

Jacob Lee
Jacob Lee

Reputation: 4700

You can use the Member.create_dm() method

@bot.event
async def on_message(message):
    if message.content.lower() == "e":
        dmchannel = await message.author.create_dm()
        await dmchannel.send("You typed E!")

Upvotes: 0

buga
buga

Reputation: 387

Here few points to note that :
message.channel.send(<message>) function is used for public responses like on sever. message.author.send(<message>) function is used for private responses or for direct message(DM).

@bot.event
async def on_message(message):
   if(message.content == 'E'):
      await message.author.send('You typed E!')`enter code here`

Upvotes: 1

FlameDev
FlameDev

Reputation: 25

I'm guessing this is what you mean:

@bot.event
async def on_message(message):
   if(message.content == 'E'):
      await message.author.send('You typed E!')

Upvotes: 1

Related Questions