@property
def randomcolours(self):
return [int(x * 255) for x in colorsys.hsv_to_rgb(random.random(), 1, 1)]
@tasks.loop(seconds=3, count=15)
async def rainbow_embed(self, _, t, d):
await self.bot.ini.edit(embed=discord.Embed(title=t, description=d, colour=discord.Colour.from_rgb(*self.randomcolours())))
I am trying to pass the 3 returned values from randomcolours
as the arguments in the colour
kwarg but I am getting a TypeError: 'list' object is not callable
, how can I do this?
randomcolours
is a @property
, so an expression like self.randomcolours
will call the function and evaluate to the list. Thus, when you call it like self.randomcolours()
, you're actually calling the list returned from the property. It's not possible to call a list, so you get the error.
How to solve:
discord.Colour.from_rgb(*self.randomcolours)
randomcolours
a property
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.