简体   繁体   English

discord.py 机器人不响应 DM 中的输入

[英]discord.py Bot does not respond to input in DMs

What I'm trying to do : To receive a response from the message author in their DMs with the bot.我正在尝试做的事情:使用机器人在他们的 DM 中接收消息作者的回复。

My problem : Bot does not respond when message is sent to it in the DMs as I am expecting.我的问题:如我所料,当消息在 DM 中发送给它时,Bot 没有响应。 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 :图片

没有回应

(Above image) No response is given despite the given conditions being met. (上图)尽管满足了给定的条件,但没有给出任何响应。

References/ Other Questions I have referred to :参考资料/我提到的其他问题

There is a problem with your check, if you print message.channel you will get:你的支票有问题,如果你打印message.channel你会得到:

Direct Message with username#1234

And if you print discord.channel.DMChannel you will get:如果你打印discord.channel.DMChannel你会得到:

<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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM