我正在尝试仅对执行!pages命令的特定用户更改bot反应,我尝试了message.author和reaction.message.author == message.author,但没有成功!
问题在于,当某人使用此命令时,它也将对其他人有用,这不是我期望的。
这是代码
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
left = '⏪'
right = '⏩'
messages = ("1", "2", "3")
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 and reaction.message.author == message.author:
print('Left')
return True
if r and reaction.emoji == right and reaction.message.author == message.author:
print('Right')
return True
return False
return check
@bot.command(pass_context=True)
async def pages(ctx):
index = 0
msg = None
action = ctx.send
while True:
res = await action(content=messages[index])
if res is not None:
msg = res
l = index != 0
r = index != len(messages) - 1
if l:
await msg.add_reaction(left)
if r:
await msg.add_reaction(right)
react, user = await bot.wait_for('reaction_add', check=predicate(msg, l, r))
if react.emoji == left and user == ctx.author:
index -= 0
await msg.delete()
print(f'Left {index}')
action = ctx.send
elif react.emoji == right and user == ctx.author:
index += 1
await msg.delete()
print(f'Right {index}')
action = ctx.send
bot.run('token')
答案 0 :(得分:0)
您可能需要对照user
检查ctx.author
(reaction.message.author
将是您的漫游器)。这意味着我们在创建支票时需要通过作者:
def predicate(message, l, r, author):
def check(reaction, user):
if author.id != user.id:
return False
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
react, user = await bot.wait_for('reaction_add', check=predicate(msg, l, r, ctx.author))