How can you make a Discord bot (using discord.py) test for responses in dms?

Viewed 275

I am working on a project for verification purposes, but I am having trouble finding any sources that point to how you can check for responses and their validity, as well as whether or not it is a response to the bot question. Any suggestions or sources would be greatly appreciated.

1 Answers

You can either use the on_message event or wait_for

@bot.event
async def on_message(message):
    # Checking if the type of the channel is `discord.DMChannel`
    if isinstance(message.channel, discord.DMChannel):
        await message.channel.send("Responding in dm's")
@bot.command()
async def command(ctx):
    def check(message):
        # Checking if the author of the message is the same as the author of the command
        # And if the channel is a `discord.DMChannel` instance
        return message.author == ctx.author and isinstance(message.channel, discord.DMChannel)

    await ctx.author.send("Waiting for a reply in dm's")  
    message = await bot.wait_for('message', check=check)
    await ctx.author.send("Responding in dm's")

Reference:

Related