.endswith方法引发异常“ AttributeError:'str'对象没有属性'value'”

问题描述

我正在尝试使用库discord.py创建“派系机器人”。我的机器人的create命令引发异常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'

是什么原因造成的,我该如何解决?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)