Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python discord.py wait_for(';reaction#u add';)与直接消息的功能不同_Python_Discord_Discord.py - Fatal编程技术网

Python discord.py wait_for(';reaction#u add';)与直接消息的功能不同

Python discord.py wait_for(';reaction#u add';)与直接消息的功能不同,python,discord,discord.py,Python,Discord,Discord.py,我的目标是让机器人对自己的消息做出反应,然后在发送原始命令的用户也做出反应的情况下,在该通道中发送回复。现在,如果命令是在服务器通道中发送的,那么该函数就可以工作,但是如果将其作为直接消息发送给bot,它不会等待您的反应。通过在检查期间打印user.id和ctx.author.id的值,我注意到机器人有时会检查自己的反应(user.id返回机器人的id)。我不确定这是否相关,因为它在服务器通道中等待正确用户的反应 和的API文档 我希望这个功能在服务器上工作,并直接向机器人发送消息,我是否遗漏了

我的目标是让机器人对自己的消息做出反应,然后在发送原始命令的用户也做出反应的情况下,在该通道中发送回复。现在,如果命令是在服务器通道中发送的,那么该函数就可以工作,但是如果将其作为直接消息发送给bot,它不会等待您的反应。通过在检查期间打印
user.id
ctx.author.id
的值,我注意到机器人有时会检查自己的反应(
user.id
返回机器人的id)。我不确定这是否相关,因为它在服务器通道中等待正确用户的反应

和的API文档

我希望这个功能在服务器上工作,并直接向机器人发送消息,我是否遗漏了什么?谢谢

@bot.command()
async def hello(ctx):
    msg = await ctx.send(f'Hi {ctx.author.mention}')
    await msg.add_reaction('✅')

    def check(reaction, user):
        print(user.id, ctx.author.id)
        return reaction.message.id == msg.id and user.id == ctx.author.id and str(reaction.emoji) == '✅'

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
    except asyncio.TimeoutError:
        pass
    else:
        await ctx.send('success')

这毕竟是一个意图问题,和post一样的权限问题。
intents=discord.intents.default()
之后,您还需要为您的应用程序启用服务器成员特权intent,并在代码中设置
intents.members=True
,以授予机器人在DMs中工作所需的权限

您可以检查反动id

    def check(reaction, user):
        # let the user id str 
        print(str(reaction.author.id), str(ctx.author.id))
        return reaction.message.id == msg.id and reaction.author.id == ctx.author.id and str(reaction.emoji) == '✅'

    try:
        # wait for the reactions
        reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
    except asyncio.TimeoutError as error:
        pass
    else:
        # except an error
        await ctx.send('success')

你确定它不起作用吗?我无法复制这个问题。你能把你用来等待反应的代码放在DMs中吗?谢谢你的格式帮助-它在hello函数中的try:reaction,user=wait bot下。wait_for('reaction_add',timeout=30.0,check=check)你在等待,直到调用命令的人对发送的消息做出反应,如果我对随机消息做出反应(例如在DMs中)它将不起作用,它必须是bot发送的消息。不是一条随机消息,调用DMs中的命令,并对bot回复的消息作出反应。它对我起作用,你启用了什么意图?