기존 역할의 색상을 설정하려면?
이것은 역할을 만드는 코드입니다.
roles = ["SSS | Weeb", "SS Rang | Weeb", "S Rang | Weeb", "A Rang | Weeb", "B Rang | Weeb",
"C Rang | Weeb", "D Rang | Weeb", "E Rang | Weeb", "F Rang | Weeb", "Junior Rang | Weeb"]
for i in roles:
seasons = discord.utils.get(message.guild.roles, name=str(i))
if str(seasons) == str(i):
pass
else:
await message.guild.create_role(name=str(i))
이제 나는 거기에 sth를 설정하고 싶습니다.
roles = ["SSS | Weeb", "SS Rang | Weeb", "S Rang | Weeb", "A Rang | Weeb", "B Rang | Weeb",
"C Rang | Weeb", "D Rang | Weeb", "E Rang | Weeb", "F Rang | Weeb", "Junior Rang | Weeb"]
colors = ["red, green", "blue"] # and much more
for i in range(len(roles)):
seasons = discord.utils.get(message.guild.roles, name=str(roles[i]))
if str(seasons) == str(roles[i]):
pass
else:
await message.guild.create_role(name=str(roles[i]))
-> await message.guild.add_color_to_role(role_name=str(roles[i]), color=colors[i])
나는 아무것도 찾지 못했다 ...
같은 것은이 같은 없어 Guild.add_color_to_role
그것의, Role.edit
및 역할을 만들 때 또한 색상을 전달할 수하는 kwargs로로 색상을 전달합니다
# Editing the role
await role.edit(colour=discord.Colour.blue())
# Creating a role with the color
await guild.create_role(name="whatever", colour=discord.Colour.blue())
16 진수 값을 kwarg 색상에 전달할 수도 있습니다.
await guild.create_role(name="whatever", colour=0xff0000) # Red color
따라서 색상 목록은 discord.Colour
인스턴스 목록이거나 정수 목록이어야합니다.
colors = [0xff0000, discord.Colour.blue(), 0x00ff00]
두 목록을 동시에 살펴 보려면 zip
함수를 사용할 수 있습니다 (참고 : 두 목록은 길이가 같아야합니다).
role_names = ["name1", "name2", "name3"]
role_colors = [0xff0000, 0x00ff00, 0x0000ff]
for name, color in zip(role_names, role_colors):
print(f"Name: {name}, color: {color}")
# Name: name1, color: 0xff0000
# Name: name2, color: 0x00ff00
# ...
코드는 다음과 같습니다.
role_names = ["name1", "name2", "name3"]
role_colors = [0xff0000, 0x00ff00, 0x0000ff] # The default color is 0x000000 (white)
for name, color in zip(role_names, role_colors):
print(f"Name: {name}, color: {color}") # -> Name: name1, color: 0xff0000 ...
# Getting the role
role = discord.utils.get(message.guild.roles, name=name)
# Checking if the role exists (in other words - if the `role` variable is not a NoneType)
if role is not None:
# Role does not exist, create it here
role = await message.guild.create_role(name=name, colour=color)
편집하다
다음과 같은 색상을 사용하려면 #5482a5
color = "#5482a5"
color = color[1:] # removing the initial `#`
color = int(color, 16) # pass this as the colour kwarg
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다