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

2024-05-14 00:35:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试做的事情:通过bot在其DMs中接收来自消息作者的响应

我的问题:在DMs中向Bot发送消息时,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

(上图)尽管满足给定条件,但未给出响应

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


Tags: pytestsend消息messageresponsecheckbot
1条回答
网友
1楼 · 发布于 2024-05-14 00:35:33

您的支票有问题,如果您打印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"

相关问题 更多 >