Python Discord.py wait_for()我的Cog的意外关键字

2024-10-04 09:23:31 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在cog文件中为discord bot使用wait_for()时,出现了一个意外错误

错误说明:

wait_for() got an unexpected keyword argument 'check'

我怎样才能解决这个问题

守则:

while tourGrange == True and finGrange == 0:

            tourGrange = False
            avance = 0
            choix = random.choice(situation)

            await ctx.message.delete()

            outilsMecanique = ["Clé à molette", "Clé à tube", "Pinces combinées", "Marteau à griffes", "Tournevis", "clé"]
            outilsAgricole = ["Faux", "Hache", "Binette", "Pelle", "Rateau", "Scie", "Brouette", "clé"]
            avance = 1

            #Vérifie l'auteur de la réaction
            def checkEmojiGrange(reaction, user):
                if avance == 1:
                    return user == ctx.message.author and message.id == reaction.message.id and (str(reaction.emoji) == "🔧" or str(reaction.emoji) == "🚜")
                if avance == 2:
                    return user == ctx.message.author and message.id == reaction.message.id and (str(reaction.emoji) == "✅" or str(reaction.emoji) == "❌")

            #Message de commencement
            await ctx.send(f"""```diff\n+ Aprés être rentrer dans la grange.\n+ {ctx.message.author.name} voit énormément d'outils agricoles, ainsi qu'un vieux tracteur !```""")
            await asyncio.sleep(1)
            message = await ctx.send(f"""```diff\n- Souhaitez-vous regardé ces outils agricoles 🔧 ou le tracteur 🚜 ?```""")

            #choix de la fouille
            await message.add_reaction("🔧")
            await message.add_reaction("🚜")

            #situation en fonction de la reaction
            try:
                reaction, user = await asyncio.wait_for("reaction_add", timeout = 10, check = checkEmojiGrange)

            except Exception as e:
                print(e)
                await ctx.send("La fouille à été annulée automatiquement.")
                messages = await ctx.channel.history(limit=0+3).flatten()
                await asyncio.sleep(4)
                for message in messages:
                    await message.delete()
                tourGrange, finGrange = True, 1
                return

Tags: andidmessagefordeawaitlactx
3条回答

我创造了它,现在它说:

wait_for() missing 1 required positional argument: 'event'

所以我设置如下:

reaction, user = await client.wait_for(event = "reaction_add", timeout = 10, check = checkEmojiGrange)

现在:

wait_for() missing 1 required positional argument: 'self'

这是因为您应该使用await client.wait_for(),其中client是您的^{}对象

因此,在您的代码中,请使用:

reaction, user = await client.wait_for("reaction_add", timeout = 10, check = checkEmojiGrange)

而不是:

reaction, user = await asyncio.wait_for("reaction_add", timeout = 10, check = checkEmojiGrange)

^{}没有check关键字。您必须改用^{}

相关问题 更多 >