要使漫游器对最后一条消息做出反应,或者对消息ID为

时间:2019-02-19 22:27:25

标签: python python-3.x discord discord.py

我正在尝试使机器人对命令发送的最后一条消息做出反应,但我尝试过,但它给我一个错误,即Message Argument must be a Message另外,我还试图使机器人对做出反应一条带有用户给出的消息ID的消息,以下是我尝试做的事情

# (Most important) This should react on the last message with the  emoji (Not this message it self)
@client.command(pass_context=True)
async def react(ctx):
    Channel=ctx.message.channel
    logs = client.logs_from(Channel, limit=1) #This is meant to check the last (1) message
    await client.add_reaction(logs, emoji="")

还有其他脚本

# (Least important) This should react to a message that has the message id you give
@client.command(pass_context=True)
async def like(ctx,Message_id):
    message=Message_id
    await client.add_reaction(message, emoji="")

1 个答案:

答案 0 :(得分:2)

对于第一个示例,logs_from是一个returns a generator的协程(需要等待),因此您可以执行类似的操作

async for msg in logs:
  await client.add_reaction(msg, emoji="")

对于第二个示例,您正在将命令的第一个参数作为消息传递进来,但是却得到了消息ID的字符串。
您需要先将该字符串转换为整数,然后找到具有该ID的消息

message= await client.get_message(ctx.message.channel, int(Message_id))
await client.add_reaction(message, emoji="")

第一个示例的注释
如果您想获得倒数第二条消息,可以执行

await logs.__anext__()
await client.add_reaction(await logs.__anext__(), emoji="")