discord 使用十六进制颜色创建角色 (pycord)
discord create role with hex color (pycord)
所以我正在尝试创建一个带有十六进制颜色代码的角色
async def createrole(server, name, hexcolor):
role = await server.create_role(name=name, color=hexcolor, mentionable=False)
return role
但我收到此错误:
Traceback (most recent call last):
File "D:\PyCharm Projects\TWD-Booster\venv\lib\site-packages\discord\commands\core.py", line 113, in wrapped
ret = await coro(arg)
File "D:\PyCharm Projects\TWD-Booster\venv\lib\site-packages\discord\commands\core.py", line 766, in _invoke
await self.callback(ctx, **kwargs)
File "D:/PyCharm Projects/TWD-Booster/main.py", line 99, in boosterrole
role = await createrole(ctx.author.guild, name, colorformat)
File "D:/PyCharm Projects/TWD-Booster/main.py", line 242, in createrole
role = await server.create_role(name=name, color=hexcolor, mentionable=False)
File "D:\PyCharm Projects\TWD-Booster\venv\lib\site-packages\discord\guild.py", line 2568, in create_role
fields["color"] = actual_colour.value
AttributeError: 'str' object has no attribute 'value'
这是颜色字符串:
hexcolor = "0xffff00"
我的问题是,是否可以使用十六进制代码创建角色,还是必须使用 rgb?
您无需将 hexcolor
值放在引号中
hexcolor = 0xffff00
await server.create_role(name=name, color=hexcolor, mentionable=False)
您也可以只使用 discord.Color 来设置颜色。
它将是:
async def createrole(server, name, hexcolor):
hexcolor = discord.Color(0xffff00)
role = await server.create_role(name=name, color=hexcolor, mentionable=False)
return role
所以我正在尝试创建一个带有十六进制颜色代码的角色
async def createrole(server, name, hexcolor):
role = await server.create_role(name=name, color=hexcolor, mentionable=False)
return role
但我收到此错误:
Traceback (most recent call last):
File "D:\PyCharm Projects\TWD-Booster\venv\lib\site-packages\discord\commands\core.py", line 113, in wrapped
ret = await coro(arg)
File "D:\PyCharm Projects\TWD-Booster\venv\lib\site-packages\discord\commands\core.py", line 766, in _invoke
await self.callback(ctx, **kwargs)
File "D:/PyCharm Projects/TWD-Booster/main.py", line 99, in boosterrole
role = await createrole(ctx.author.guild, name, colorformat)
File "D:/PyCharm Projects/TWD-Booster/main.py", line 242, in createrole
role = await server.create_role(name=name, color=hexcolor, mentionable=False)
File "D:\PyCharm Projects\TWD-Booster\venv\lib\site-packages\discord\guild.py", line 2568, in create_role
fields["color"] = actual_colour.value
AttributeError: 'str' object has no attribute 'value'
这是颜色字符串:
hexcolor = "0xffff00"
我的问题是,是否可以使用十六进制代码创建角色,还是必须使用 rgb?
您无需将 hexcolor
值放在引号中
hexcolor = 0xffff00
await server.create_role(name=name, color=hexcolor, mentionable=False)
您也可以只使用 discord.Color 来设置颜色。 它将是:
async def createrole(server, name, hexcolor):
hexcolor = discord.Color(0xffff00)
role = await server.create_role(name=name, color=hexcolor, mentionable=False)
return role