'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!
Solution 1:[1]
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!')
Solution 2:[2]
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`
Solution 3:[3]
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!")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | FlameDev |
| Solution 2 | Martian Coder |
| Solution 3 |
