【发布时间】:2021-04-18 10:10:59
【问题描述】:
我正在制作一个充当漫画阅读器的命令,我想使用wait_for 等待用户的反应,然后相应地前进或后退。但是,我对如何实现它感到困惑。
@commands.command()
async def read_manga(self, ctx, page=1):
page -= 1
image_urls = ['image1.url', 'image2.url', 'image3.url', 'etc.urls']
message = await ctx.send(image_urls[page])
def backward_check(reaction, user):
return user == ctx.message.author and str(reaction.emoji) == '◀️'
def forward_check(reaction, user):
return user == ctx.message.author and str(reaction.emoji) == '▶️'
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=forward_check)
except asyncio.TimeoutError:
print('Timed Out')
else:
await message.edit(content=image_urls[page+1])
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=backward_check)
except asyncio.TimeoutError:
print('Timed Out')
else:
await message.edit(content=image_urls[page-1])
就像现在一样,机器人只会响应前向检查而不是后向检查。此外,如果我对 ▶️ 做出反应、未做出反应,然后再次对 ▶️ 做出反应,机器人将不会检测到。我该如何解决这些问题?
【问题讨论】:
-
看起来您正在尝试实现一个菜单,您可以使用this 菜单扩展并省去一些麻烦
标签: python-3.x discord.py