我从Python开始,我正在制作一个Discord机器人几个星期,现在,当我试图在我的机器人中制作一个“投票系统”时,我遇到了如下错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'author'
我的代码:
@client.command()
async def hlasovani(self, ctx, volba1, volba2, *, tema):
embed = discord.Embed(title = tema,description = f":one: {volba1}\n\n:two: {volba2}",color = ctx.author.color,timestamp = datetime.datetime.utcnow())
embed.set_footer(text = f"Hlasování zahájil {ctx.author.name}")
embed.set_thumbnail(url = ctx.author.avatar_url)
message = await ctx.send(embed = embed)
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
await asyncio.sleep(5)
newmessage = await ctx.fetch_message(message.id)
onechoice = await newmessage.reactions[0].users().flatten()
secchoice = await newmessage.reactions[1].users().flatten()
vysledek = "REMÍZA!"
if len(onechoice)>len(secchoice):
vysledek = volba1
elif len(secchoice)<len(onechoice):
vysledek = volba2
embed = discord.Embed(title = tema, description = f"Výsledek: {vysledek}", color = ctx.author.color, timestamp = datetime.datetime.utcnow())
embed.set_footer(text = f"{volba1} || {volba2}")
await newmessage.edit(embed = embed)
我真的很感激任何帮助
由于您使用的是
@client.command()
而不是@commands.command()
,因此我假定您的命令不在cog或其他类中。如果是这种情况,则需要从命令中删除self
参数相关问题 更多 >
编程相关推荐