我正在尝试使用库 discord.py 来创建一个“派系机器人”。我的机器人的创建命令引发了异常AttributeError: 'str' object has no attribute 'value'
。这是我的代码:
@commands.command()
async def c(self, ctx, color: str, *, name: str):
name_lower = name.lower()
if name_lower.endswith("owner"):
embed = discord.Embed(
title=":x: Error Creating Faction",
colour=discord.Colour.purple(),
description="Make sure your faction name doesn't end with the word **owner**."
)
await ctx.send(embed=embed)
else:
if name_lower.endswith("faction"):
role_name = name_lower.capitalize()
else:
role_name = f"{name_lower.capitalize()} Faction"
await ctx.guild.create_role(name=role_name, color=color)
await ctx.guild.create_role(name=f"{role_name} Owner", color=color)
await ctx.message.add_reaction(":white_check_mark:")
该命令将颜色字符串和名称字符串作为输入。在第 5 ( if name_lower.endswith("owner"):
) 行,它检测小写版本的 是否以name
单词“owner”结尾。问题是,这条线引发了异常AttributeError: 'str' object has no attribute 'value'
。
是什么原因造成的,我该如何解决?