分页-Discord.py重写

分页-Discord.py重写,discord.py,discord.py-rewrite,Discord.py,Discord.py Rewrite,我一直在试图发出一个命令,显示一些信息,然后,当我对一个表情做出反应时,它应该显示另一组信息 我尝试使用的部分,特别是第335到393行中的部分 让它工作。然而,它什么也不做。甚至没有错误消息 这就是我现在使用的代码 def check_react(reaction, user): if reaction.message.id != msg.id: return False if user != ctx.message.au

我一直在试图发出一个命令,显示一些信息,然后,当我对一个表情做出反应时,它应该显示另一组信息

我尝试使用的部分,特别是第335到393行中的部分 让它工作。然而,它什么也不做。甚至没有错误消息

这就是我现在使用的代码

        def check_react(reaction, user):
        if reaction.message.id != msg.id:
            return False
        if user != ctx.message.author:
            return False
        return True
    res, user = await bot.wait_for('reaction_add', check=check_react, timeout=None,)
    if user != ctx.message.author:
        print('if user != ctx.message.author:')
    elif '⬅️' in str(res.emoji):
        page -=1
        print(page)
        embed = discord.Embed(title='generic title', description='generic description', color=0x52fffc)
        await msg.edit(embed=embed)
    elif '➡️' in str(res.emoji):
        page +=1
        print(page)
        embed = discord.Embed(title='generic title 2', description='generic description 2', color=0x52fffc)
        await msg.edit(embed=embed)
它似乎停在

等待机器人。等待('反应添加',…)


为什么呢?我怎样才能使代码工作?顺便说一句,如果需要的话,我很乐意提供更多的代码。

忘记了这一点,我最终找到了答案。我是这样做的:

首先,我将页面的所有内容放在一个列表中。每个条目都是一页

然后我定义一个函数作为检查。这将把反应侦听器限制为发送的实际嵌入,并防止除命令调用程序之外的任何人作出反应。很抱歉出现任何格式错误

def check(reaction, user):
   return reaction.message.id == msg.id and user == ctx.author #msg.id is the id of the embed sent by the bot.

page = 0

while True: #can be changed to a variable to let it work a certain amount of times.
   try:
       reaction, _ = await bot.wait_for('reaction_add', timeout= 20.0, check=check)
       if reaction.emoji == 'emote of choice here' and page > 0:
           page -= 1
           embed = discord.Embed(title='Title Here', description=pages[page]
           await msg.edit(embed=embed)
       if reaction.emoji == 'emote of choice here' and page < len(pages) -1:
           page += 1
           embed = discord.Embed(title='Title Here', description= pages[page]
           await msg.edit(embed=embed)
   except asyncio.TimeoutError:
      #do stuff here, could be pass or a message saying the timeout has been reached or something similar.
def检查(反应,用户):
return reaction.message.id==msg.id和user==ctx.author#msg.id是bot发送的嵌入的id。
第页=0
虽然为True:#可以更改为变量,使其工作一定的时间。
尝试:
反应,u=wait bot.wait_for('reaction_add',timeout=20.0,check=check)
如果reaction.emoji==“此处选择表情”且页面>0:
第-=1页
embed=discord.embed(title='title Here',description=pages[page]
等待消息编辑(嵌入=嵌入)
如果reaction.emoji=='emote of choice here'和page
更好、更简单的方法是使用

以下是一个例子:

@commands.command()
异步def分页(自,ctx):
embed1=discord.Embed(color=ctx.author.color)。添加_字段(name=“Example”,value=“Page 1”)
embed2=discord.Embed(color=ctx.author.color)。添加_字段(name=“Example”,value=“Page 2”)
embed3=discord.Embed(color=ctx.author.color)。添加_字段(name=“Example”,value=“Page 3”)
paginator=DiscordUtils.Pagination.CustomEmbeddePaginator(ctx,remove\u=True)
paginator.add_反应('⏮️', “第一条”)
paginator.add_反应('⏪', “背面”)

paginator.add_reaction(‘“它似乎停止在:wait bot.wait_for(‘reaction_add’)。函数等待一个reaction_add。或者换句话说,它停止在该行。出于某种原因,bot停止在while循环,而不继续执行该命令