discord.py Bot 不响应 DM 中的输入

时间:2020-12-23 02:03:04

标签: python discord.py

我想要做什么:接收消息作者在他们与机器人的 DM 中的回复。

我的问题:当消息在 DM 中发送给它时,Bot 没有响应,正如我所期望的那样。没有错误消息。

代码

@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

图片

No response is given

(上图)尽管满足给定的条件,但没有给出任何响应。

我提到的参考资料/其他问题

1 个答案:

答案 0 :(得分:1)

你的支票有问题,如果你打印 message.channel 你会得到:

Direct Message with username#1234

如果你打印 discord.channel.DMChannel 你会得到:

<class 'discord.channel.DMChannel'>

您会注意到它们是两种不同的东西,将您的支票更改为此应该可以解决问题:

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