Skip to content

Commit 88d839c

Browse files
authored
Merge pull request #9 from Ditttt/main
2 parents 0e9d2e2 + f651739 commit 88d839c

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

snippets/snippets.code-snippets

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,89 @@
254254
]
255255
},
256256

257+
"discord.py embed page reaction template": {
258+
"prefix": "!embpagere",
259+
"body": [
260+
"# note : variable per page can be taken from the parameter command that you created",
261+
"emoji_nextpage = discord.utils.get(${1|bot,client,self.bot|}.emojis, name=\"$2\")",
262+
"emoji_backpage = discord.utils.get(${1|bot,client,self.bot|}.emojis, name=\"$4\")",
263+
"emoji_firstpage = discord.utils.get(${1|bot,client,self.bot|}.emojis, name=\"$5\")",
264+
"emoji_lastpage = discord.utils.get(${1|bot,client,self.bot|}.emojis, name=\"$6\")",
265+
"emoji_lock = discord.utils.get(${1|bot,client,self.bot|}.emojis, name=\"$7\")",
266+
"${8:formart_lb} = []",
267+
"for x in data:",
268+
" ${8:formart_lb}.append(\"$9\")",
269+
"num_of_${10:embeds} = ceil((len(${8:formart_lb}) + 1) / ${15|perpage,1,2,3,4,5,6,7,8,9,10|})",
270+
"${10:embeds} = []",
271+
"page_format = '(Page {}/{})'",
272+
"for i in range(1, num_of_${10:embeds} + 1):",
273+
" ${10:embeds}.append(discord.Embed($10).set_footer(text=page_format.format(i, num_of_${10:embeds})))",
274+
"${11:embed_index} = 0",
275+
"for index, element in enumerate(${10:formart_lb}):",
276+
" ${10:embeds}[${11:embed_index}].add_field(name=f'**{index + 1}.**', value='{}'.format(element), inline=${12|True,False|})",
277+
" if (index + 1) % ${15|perpage,1,2,3,4,5,6,7,8,9,10|} == 0:",
278+
" ${11:embed_index} += 1",
279+
"buttons = [emoji_firstpage,emoji_backpage,emoji_lock,emoji_nextpage,emoji_lastpage]",
280+
"curent = 0",
281+
"msg = await ctx.send(embed=${10:embeds}[curent])",
282+
"for bt in buttons:",
283+
" try:",
284+
" await msg.add_reaction(bt)",
285+
" except:",
286+
" pass",
287+
"try:",
288+
" reaction, user = await ${1|bot,client,self.bot|}.wait_for('reaction_add', check=lambda r, u: ${13:u == ctx.author and r.message.channel.id == ctx.channel.id and and r.emoji in buttons}, timeout=${14|15,30,45,60,120,300,900|})",
289+
"except asyncio.TimeoutError:",
290+
" for btn in buttons:",
291+
" try:",
292+
" await msg.clear_reaction(btn)",
293+
" except:",
294+
" pass",
295+
"else:",
296+
" previous_page = curent",
297+
" if reaction.emoji == buttons[0]:",
298+
" curent = 0",
299+
" try:",
300+
" await msg.remove_reaction(str(reaction.emoji), user)",
301+
" except:",
302+
" pass",
303+
" await msg.edit(embed=${10:embeds}[curent])",
304+
" elif reaction.emoji == buttons[1]:",
305+
" if curent > 0:",
306+
" curent -= 1",
307+
" try:",
308+
" await msg.remove_reaction(str(reaction.emoji), user)",
309+
" except:",
310+
" pass",
311+
" if curent != previous_page:",
312+
" await msg.edit(embed=${10:embeds}[curent])",
313+
" elif reaction.emoji == buttons[3]:",
314+
" if curent < num_of_${10:embeds} - 1:",
315+
" curent += 1",
316+
" try:",
317+
" await msg.remove_reaction(str(reaction.emoji), user)",
318+
" except:",
319+
" pass",
320+
" if curent != previous_page:",
321+
" await msg.edit(embed=${10:embeds}[curent])",
322+
" elif reaction.emoji == buttons[4]:",
323+
" curent = num_of_${10:embeds} - 1",
324+
" try:",
325+
" await msg.remove_reaction(str(reaction.emoji), user)",
326+
" except:",
327+
" pass",
328+
" if curent != previous_page:",
329+
" await msg.edit(embed=${10:embeds}[curent])",
330+
" elif reaction.emoji == buttons[2]:",
331+
" await msg.remove_reaction(buttons[2], ctx.author)",
332+
" for btns in buttons:",
333+
" try:",
334+
" await msg.clear_reaction(btns)",
335+
" except:",
336+
" pass",
337+
]
338+
},
339+
257340
"discord.py Exception":{
258341
"prefix": "!except",
259342
"body": [

0 commit comments

Comments
 (0)