I tried so me code and didn’t work for waiting messages so I wanna know how to wait for message in DM if the user sent a command in a channel using discord.py.
UPDATED
This is the last code which worked as example according to what the accepted answer!
async def command_name(ctx): await ctx.send("Send a message in DM.") def check(m): return m.author == ctx.author and m.guild is None msg = await client.wait_for('message', check=check) # Do something after they sent a DM```
Advertisement
Answer
Use the built-in wait_for
for this. You can write a custom check
to see if it’s a DM channel or not. The check is a function that returns True
if your function should stop waiting, or False
if it shouldn’t. You only slightly have to modify the example from the docs to get your desired result:
@client.command() async def command_name(ctx): await ctx.send("Send a message in DM.") def check(m): return m.author == ctx.author and m.guild is None msg = await client.wait_for('message', check=check) # Do something after they sent a DM