I'm trying to use the library discord.py to create a "faction bot". The create command of my bot raises the exception AttributeError: 'str' object has no attribute 'value'
. Here is my code:
@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:")
The command takes a color string and a name string as an input. On line 5 (if name_lower.endswith("owner"):
) it detects whether a lowercase version of name
ends with the word "owner" or not. The problem is, this line raises the exception AttributeError: 'str' object has no attribute 'value'
.
What is causing it and how can I fix it?