Answer the question
In order to leave comments, you need to log in
How to create role with color and name in discord.py?
I want a person to create their own role for a fee, which will have the name and color that he wants.
My code:
@commands.command(
aliases=['создатьроль']
)
async def createrole(self,ctx, name: str, color):
abalance = self.collection.find_one({"_id": ctx.author.id})["balance"]
if abalance >= 4000:
guild = ctx.guild
role = await guild.create_role(name=name, colour=discord.Colour(color))
#role = discord.utils.get(ctx.guild.roles, name="role to add name")
user = ctx.message.author
await user.add_roles(role)
emb=discord.Embed(
title='Создание Личной Роли',
description=f'{ctx.author.mention}, вы успешно **создали** роль {role.mention} за 4000 осколков.'
)
emb.set_thumbnail(url=ctx.author.avatar_url)
await ctx.send(embed=emb)
else:
emb=discord.Embed(
title='Создание Личной Роли',
description=f'{ctx.author.mention}, у вас нет 4000 осколков.'
)
Answer the question
In order to leave comments, you need to log in
discord.Color takes an integer (int) as an argument in the constructor. You are passing a string (because if no argument type is specified, discord.py will pass the argument string itself).
Either pass a number:
Or use a color converter :
async def cmd(ctx, arg: int):
async def cmd(ctx, arg: discord.Color):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question