0

Example of what I mean:

I want to replace a method 'method()' with a variable name that stores the method

Here is some code:

embed = discord.Embed(title="This is a title", description="This is a description", color=discord.Color.red())

focus on the COLOR at the end. As you can see, I must first specify 'discord.Color' then I should put a period '.' and then the function/method. If I want the color to be RED for example, I should use red() and if I wanted it to be GREEEN, then I would use green(). But what if I want the color to be of user input?

This is what I tried:

Try to understand what I was trying to do:

# Let us assume that the chosen color was blue:
chosen_color = "blue"
embed = discord.Embed(title=title, description=description, color=discord.Color.(chosen_color)())

So what I tried to do was to state that the color is:

discord.Color.blue()

By doing:

discord.Color.(chosen_color)()

But it does not work like that. I replaced what should have been 'blue' with the variable 'chosen_color' and then put the brackets to show that it is a method. The "blue" is a STRING in the first place, and if it was not, I am sure that it would still not work anyway.

How would you approach this? Would appreciate some help, thanks

htmler
  • 1
  • 1
  • `getattr(discord.Color, 'green')()` [here](https://docs.python.org/3/library/functions.html#getattr) is the documentation – Nullman May 01 '22 at 13:06

0 Answers0