discord.py 봇이 DM의 입력에 응답하지 않습니다.

Dec 23 2020

내가하려는 작업 : 봇과 함께 DM의 메시지 작성자로부터 응답을 수신합니다.

내 문제 : 내가 예상대로 DM에 메시지를 보낼 때 봇이 응답하지 않습니다. 오류 메시지가 없습니다.

코드 :

@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

이미지 :

(위 이미지) 주어진 조건이 충족 되어도 응답이 없습니다.

내가 언급 한 참조 / 기타 질문 :

  • Discord.py 채널이 DM인지 확인
  • discord.DMChannel API 참조
  • Discord.py-특정 메시지로 DM에 답장
  • Discord.py 봇 : 내 discord 봇이 설문 조사 등 사용자가 DM에서 사용하는 명령에 대한 응답을 보내도록하려면 어떻게해야합니까?

답변

1 NuKeFluffy Dec 23 2020 at 09:49

수표에 문제가 있습니다. 인쇄 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"