discord.py';协同程序';对象没有属性';反应';错误
我在上面的代码中得到以下错误discord.py';协同程序';对象没有属性';反应';错误,discord,discord.py,Discord,Discord.py,我在上面的代码中得到以下错误 @bot.command() async def voto(ctx, id, num_people): msg = ctx.fetch_message(id) winners = [] total_users = [] reactions = msg.reactions for reaction in reactions: users = await reaction.users().flatten()
@bot.command()
async def voto(ctx, id, num_people):
msg = ctx.fetch_message(id)
winners = []
total_users = []
reactions = msg.reactions
for reaction in reactions:
users = await reaction.users().flatten()
for user in users:
total_users.append(user)
for i in range(num_people):
winners.append(i.name)
winners_msg = '\n'.join(winners)
await ctx.send(f"{winners_msg}\nHas won")
我想修复,但我得到了一个错误
请帮帮我
我在您的代码ctx中使用了一个翻译器。fetch_message(id)是一个协同程序,因此应该等待它,这就是您得到的错误 将该行替换为:
msg=wait ctx.fetch_message(id)
在您的代码中ctx.fetch_message(id)
是一个协同程序,因此应该等待它,这就是您收到的错误
将该行替换为:
msg=wait ctx.fetch_message(id)
用于范围内的i(num_people):TypeError:'str'对象不能解释为整数
我正在获取该错误使用范围内(int(num_people))的。虽然最好的做法是有一个更明确的函数:async def voto(ctx,id:int,num_people:int):
用于范围内的i(num_people):TypeError:“str”对象不能解释为整数
我得到了那个错误使用用于范围内(int(num_people))
。虽然最好的做法是有一个更明确的函数:async def voto(ctx,id:int,num\u people:int):
File ".\Testing.py", line 24, in voto
reactions = msg.reactions
AttributeError: 'coroutine' object has no attribute 'reactions'
The above exception was the direct cause of the following exception:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback