首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >赋值前引用的pagination_needed

赋值前引用的pagination_needed
EN

Stack Overflow用户
提问于 2020-11-19 01:25:58
回答 1查看 20关注 0票数 0
代码语言:javascript
运行
复制
    @commands.command()
    async def tags(self, ctx):
        global names
        names = []
        async with aiosqlite.connect('s137_guild_values') as db:
            async with db.execute('SELECT name FROM tag_list WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
                async for row in cursor:
                    value = row
                    value = list(value)
                    names.append(value[0])
        if len(names) != 0:
            STOP = False
            global pagination_dict
            pagination_dict = {}
            global amount_tags
            amount_tags = len(names)
            for x in range(1, self.max_pages):
                if (math.ceil(amount_tags / x) == self.pagination_value):
                    needed_pagination = x
                    break
            current_page = 1
            var = 1
            counter = 0
            counter_all = 0
            counter_all_eq = len(names)
            index = 0
            while True:
                pagination_dict['Page {}'.format(var)] = {}
                msg = ""
                for x in range(0, (len(names))):
                    msg += '• {}\n'.format(names[index])
                    names.remove(names[index])
                    counter += 1
                    counter_all += 1
                    if (len(names) == 0) and (counter != self.pagination_value):
                        counter = self.pagination_value
                    if counter == self.pagination_value:
                        counter = 0
                        pagination_dict['Page {}'.format(var)]['Content'] = msg
                        msg = ""
                        var += 1
                        break
                if (var >= needed_pagination) and (counter_all == counter_all_eq):
                    break
            txt = "Current Page: {}/{}".format("1", needed_pagination)
            embed = discord.Embed(title="Tags ({})".format(amount_tags), description=pagination_dict['Page {}'.format(str(current_page))]['Content'], timestamp=ctx.message.created_at, colour=discord.Colour.blue())
            embed.set_footer(text=txt)
            msg = await ctx.send(embed=embed)
            for ele in self.emojis:
                await msg.add_reaction(ele)
            async def Main(ctx, msg, needed_pagination, current_page, STOP, embed, txt):
                current_page = 1
                STOP = False
                while STOP == False:
                    def check(reaction, user):
                        return (str(reaction.emoji) and user == ctx.author) and (msg.id == reaction.message.id)

                    try:
                        reaction, user = await self.client.wait_for('reaction_add', timeout=60.0, check=check)
                    except asyncio.TimeoutError:
                        await msg.delete()
                        await ctx.message.delete()
                        STOP = True
                    if reaction.emoji == '⏪':
                        if current_page != 1:
                            current_page -= 1
                            embed = discord.Embed(title="Tags ({})".format(amount_tags), description=pagination_dict['Page {}'.format(current_page)]['Content'], timestamp=ctx.message.created_at, colour=discord.Colour.blue())
                            txt = "Current Page: {}/{}".format(current_page, needed_pagination)
                            embed.set_footer(text=txt)
                            await msg.edit(embed=embed)
                            await msg.remove_reaction(reaction, ctx.author)
                        else:
                            await msg.remove_reaction(reaction, ctx.author)
                    elif reaction.emoji == '⏩':
                        if current_page != (needed_pagination):
                            current_page += 1
                            embed = discord.Embed(title="Tags ({})".format(amount_tags), description=pagination_dict['Page {}'.format(current_page)]['Content'], timestamp=ctx.message.created_at, colour=discord.Colour.blue())
                            txt = "Current Page: {}/{}".format(current_page, needed_pagination)
                            embed.set_footer(text=txt)
                            await msg.edit(embed=embed)
                            await msg.remove_reaction(reaction, ctx.author)
                        else:
                            await msg.remove_reaction(reaction, ctx.author)
                    elif reaction.emoji == '⏹️':
                        await msg.delete()
                        await ctx.message.delete()
                        STOP = True
            x = 0
            if x == 0:
                future = asyncio.ensure_future(Main(ctx, msg, needed_pagination, current_page, False, embed, txt))
                x += 1
        else:
            await ctx.send("There Are No Tags On This Server!")

我自己编写了这些代码,但是我遇到了一个问题,它显示在赋值之前引用了"pagination_needed“。

我不知道它为什么这么说。

我已经试着找出问题出在哪里了,所以如果有人知道我会很高兴。我想尽快开始尝试一些方法来修复这个问题,因为我一直渴望让这个命令再次工作。所以任何建议都是很棒的。

EN

回答 1

Stack Overflow用户

发布于 2020-11-19 02:09:35

我通过添加两个不同的函数修复了这个问题。

一个在math.ceil的结果上加1,另一个不加。

这起作用了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64898164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档