-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
41 lines (33 loc) · 1.42 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from asyncio import TimeoutError
# emoji reactions
left = "⬅"
right = "➡"
async def paginate_embed(bot, channel, embeds):
"""
takes list of embeds and paginates them with reactions
"""
total_pages = len(embeds)
curr_page = 0
og_msg = await channel.send(embed=embeds[curr_page].set_footer(text=f"Page {curr_page+1}/{total_pages}"))
if total_pages <= 1:
return
await og_msg.add_reaction(left)
await og_msg.add_reaction(right)
def check(reaction, user):
return not user.bot and reaction.message.channel == channel and reaction.message.id == og_msg.id
try:
while True:
reaction, user = await bot.wait_for("reaction_add", timeout=120.0, check=check)
if str(reaction.emoji) == right:
if curr_page < total_pages - 1:
curr_page += 1
await og_msg.edit(embed=embeds[curr_page].set_footer(text=f"Page {curr_page+1}/{total_pages}"))
await og_msg.remove_reaction(right, user)
elif str(reaction.emoji) == left:
if curr_page > 0:
curr_page -= 1
await og_msg.edit(embed=embeds[curr_page].set_footer(text=f"Page {curr_page+1}/{total_pages}"))
await og_msg.remove_reaction(left, user)
except TimeoutError:
await og_msg.remove_reaction(left, bot.user)
await og_msg.remove_reaction(right, bot.user)