[英]Python - Discord.py - wait_for() unexpected keyword for my Cog
I have a unexpected error when i use wait_for()
in my cog file for my discord bot.当我在我的 discord 机器人的 cog 文件中使用
wait_for()
时出现意外错误。
Error say:错误说:
wait_for()
got an unexpected keyword argument 'check'wait_for()
得到一个意外的关键字参数“检查”
How i can solve this problem?我该如何解决这个问题?
the code:编码:
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
asyncio.wait_for
doesn't have check keyword. asyncio.wait_for
没有 check 关键字。 You have to use client.wait_for
instead.您必须改用
client.wait_for
。
This is because you should use await client.wait_for()
where client
is your discord.Client
object.这是因为您应该使用
await client.wait_for()
,其中client
是您的discord.Client
object。
So, in your code, use:因此,在您的代码中,使用:
reaction, user = await client.wait_for("reaction_add", timeout = 10, check = checkEmojiGrange)
instead of:代替:
reaction, user = await asyncio.wait_for("reaction_add", timeout = 10, check = checkEmojiGrange)
I create it and now it say:我创建它,现在它说:
wait_for() missing 1 required positional argument: 'event'
wait_for() 缺少 1 个必需的位置参数:“事件”
So i set like this:所以我这样设置:
reaction, user = await client.wait_for(event = "reaction_add", timeout = 10, check = checkEmojiGrange)
and now:现在:
wait_for() missing 1 required positional argument: 'self'
wait_for() 缺少 1 个必需的位置参数:'self'
For the 'self' argument i add it like this:对于“自我”论点,我这样添加:
reaction, user = await client.wait_for(self, event = "reaction_add", timeout = 10, check = checkEmojiGrange)
and now its say:现在它说:
'CogFouiller' object has no attribute 'loop'
'CogFouiller' object 没有属性 'loop'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.