我有一个命令,可以通过2个按钮来回移动图像序列:
left = '⏪'
right = '⏩'
def predicate(message, l, r):
def check(reaction, user):
if reaction.message.id != message.id or user == Bot.user:
return False
if l and reaction.emoji == left:
return True
if r and reaction.emoji == right:
return True
return False
return check
一些东西
mmsg = ("1.png", "2.png", "3.png", "4.png")
index = 0
while True:
msg = await Bot.send_file(ctx.message.channel, mmsg[index])
l = index != 0
r = index != len(mmsg) - 1
if l:
await Bot.add_reaction(msg, left)
if r:
await Bot.add_reaction(msg, right)
Bot.wait_for_reaction
reaction, ctx.message.author = await Bot.wait_for_reaction(check=predicate(msg, l, r))
if reaction.emoji == left:
index -= 1
elif reaction.emoji == right:
index += 1
await Bot.delete_message(msg)
但是,当您单击该按钮以外的其他按钮时,该命令有效,这是不应该发生的,只有执行该命令的用户才能单击该按钮,如谓词检查中所示,应该怎么做?
答案 0 :(得分:0)
predicate
检查不会对此进行检查。它只是检查反应是否来自机器人。您可以在user
上添加一个wait_for_reaction
参数,以仅接受来自该ctx.message.author
的反应:
mmsg = ("1.png", "2.png", "3.png", "4.png")
index = 0
while True:
msg = await Bot.send_file(ctx.message.channel, mmsg[index])
l = index != 0
r = index != len(mmsg) - 1
if l:
await Bot.add_reaction(msg, left)
if r:
await Bot.add_reaction(msg, right)
reaction, _ = await Bot.wait_for_reaction(check=predicate(msg, l, r), user=ctx.message.author)
if reaction.emoji == left:
index -= 1
elif reaction.emoji == right:
index += 1
await Bot.delete_message(msg)
您还正在分配给我删除的ctx.message.author
。没有理由分配给Context