Z
Z
Zakkaru2021-12-18 20:27:19
Python
Zakkaru, 2021-12-18 20:27:19

How to make sure that there is no eternal loop in the command?

I took an example from the Internet, but I don’t know how to make it so that there is no eternal loop.

left = '⏪'
right = '⏩'

messages = ("1", "2", "3","4","5")

def predicate(message, l, r):
    def check(reaction, user):
        if reaction.message.id != message.id or user == client.user:
            return False
        if l and reaction.emoji == left:
            return True
        if r and reaction.emoji == right:
            return True
        return False

    return check

@client.command()
async def help(ctx):
  
    page1 = discord.Embed (
        title = '**Главная страница**',
        description = '**Всё команды** которые были в боте здесь, смотрите что есть!\n**Важно!!!** _Бот находиться в альфа тесте ВОЗМОЖНЫЕ ПРОВИСАНИЕ ИЛИ БАГИ ПРОСТИТЕ ПОЖАЛУЙСТА_ \n\n Контакт разработчика **Sorata#0200**\n\n \n\n ссылка на сервер [Поддержки](https://discord.com/invite/5GeaVV37C8)\n Поддержать бота [ссылка](https://www.donationalerts.com/r/zahark1n)',
        color=discord.Colour.from_rgb(138, 43, 226))
    page1.set_thumbnail(url=client.user.avatar_url) 
    
    page2 = discord.Embed (
        title = '**Чатик**',
        description = '**kiss** - поцеловать собеседника \n **hug** - обнять собеседника \n **sad** - погрустить \n **smoke** - выйти покурить \n **cry** - поплакать \n **funny** - посмеяться, поугарать над кем-то \n **love** - полюбить кого-то \n **pat** - погладить собеседника \n **nom** - кушать \n **happy** - радоватся!!! \n **baka** - назвать кого-то дурашкой \n **rip** - Умереть \n**drink** - выпить с кем-то\n**tea**- наслаждатся чаём\n**sleep** - уйти спать\n**slap** - ударить\n**bite** - укусить\n**sex** - кекс ._.\nСтраница 1-4',
        color=discord.Colour.from_rgb(138, 43, 226))
    page2.set_thumbnail(url=client.user.avatar_url)

    
    page3 = discord.Embed (
        title = '**Фан**',
        description = '**anime** - лучшие аниме которые посмотрел создатель бота \n **g** - мем про гуля _ВРЕММЕНО_ \n**8ball** - предсказание о вашем будущём\n**popit** - поп ит\n Страница 2-4',
        color=discord.Colour.from_rgb(138, 43, 226))
    page3.set_thumbnail(url=client.user.avatar_url)
    
    page4 = discord.Embed (
        title = '**Разное**',
        description = '**inv** - ссылка на приглашение бота \n  \n Страница 3-4',
        color=discord.Colour.from_rgb(138, 43, 226))
    page4.set_thumbnail(url=client.user.avatar_url)

    page5 = discord.Embed (
        title = '**Новый год!!!!**',
        description = '**merrychristmas** - поздравить с новым годом!\n**giftbox** - подарить подарочек \n**celebr** - празновать с кем-то \n **christmastree** - украсить ёлку \nСтраница 4-4',
        color=discord.Colour.from_rgb(138, 43, 226))
    page5.set_thumbnail(url=client.user.avatar_url)
    
    
    pages = [page1, page2, page3, page4,page5]

    message = await ctx.send(embed = page1)
    await message.add_reaction('◀')
    await message.add_reaction('⏮')
    await message.add_reaction('⏭')
    await message.add_reaction('▶')

    def check(reaction, user):
        return user == ctx.author

    i = 0
    reaction = None

    while True:
        if str(reaction) == '⏮':
            i = 0
            await message.edit(embed = pages[i])
        elif str(reaction) == '◀':
            if i > 0:
                i -= 1
                await message.edit(embed = pages[i])
        elif str(reaction) == '▶':
            if i < 4:
                i += 1
                await message.edit(embed = pages[i])
        elif str(reaction) == '⏭':
            i = 4
            await message.edit(embed = pages[i])
        
        try:
            reaction, user = await client.wait_for('reaction_add', timeout = 30.0, check = check)
        except:
            break
 

    await message.delete()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question