4
votes

What I'm trying to do: To receive a response from the message author in their DMs with the bot.

My problem: Bot does not respond when message is sent to it in the DMs as I am expecting. There are no error messages.

Code:

@client.command()
async def test(ctx):
    await ctx.send("Sending a dm now")
    def check(message):
        return message.author == ctx.author and message.channel == discord.channel.DMChannel
    try:
        await ctx.author.send("Say test: ")
        response = await client.wait_for('message', check=check)
        if response.content.lower() == 'test':
            await ctx.send("Test successful")
        elif response.content.lower() == 'banana':
            await ctx.author.send("That works too")
    except:
        # do things here

Images:

No response is given

(Above image) No response is given despite the given conditions being met.

References/ Other Questions I have referred to:

1
This part of your check: message.channel == discord.channel.DMChannel is what is causing you the problem.Fluffy

1 Answers

1
votes

There is a problem with your check, if you print message.channel you will get:

Direct Message with username#1234

And if you print discord.channel.DMChannel you will get:

<class 'discord.channel.DMChannel'>

You will notice they are two different things, changing your check to this should fix the problem:

def check(message):
    return message.author == ctx.author and str(message.channel.type) == "private"