@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“。
我不知道它为什么这么说。
我已经试着找出问题出在哪里了,所以如果有人知道我会很高兴。我想尽快开始尝试一些方法来修复这个问题,因为我一直渴望让这个命令再次工作。所以任何建议都是很棒的。
发布于 2020-11-19 02:09:35
我通过添加两个不同的函数修复了这个问题。
一个在math.ceil
的结果上加1,另一个不加。
这起作用了。
https://stackoverflow.com/questions/64898164
复制相似问题