【发布时间】:2018-12-26 11:08:16
【问题描述】:
我正在为 Discord 开发的机器人会编译有关一个人的角色的信息,然后以一些嵌入的形式发回一个角色表。
我的很多功能都被关闭了,所以现在我正在开发天赋。我想做的一件事是让人们改变嵌入侧面小条纹的颜色,结果比我想象的要困难得多。
老实说,我已经忘记了所有我尝试过的事情,到目前为止,这已经是一个 5 小时的问题,我仍在到处尝试随机调整。
###allows the user to set the stripe color of their character sheet embed.
@character.command(name="setcol")
async def color_set(self, ctx, *, color:str):
if "#" in color:
color = color.replace("#", "")
member = ctx.message.author
col = discord.Color(value=int(color, 16))
await self.config.member(member).color.set(col.to_rgb())
await asyncio.sleep(1)
col = await self.config.member(member).color()
pvw = discord.Embed(name="Preview", description="Preview", color=discord.Color.from_rgb(*col))
await ctx.send(embed=pvw)
await ctx.send("{}".format(col))
预期:
##character setcol 00fe00:
将 00fe00 转换为 discord.color() 对象,
将对象转换为字符串,
将字符串保存在颜色配置变量中,
将字符串转回 discord.Color() 对象,
返回具有正确颜色的预览嵌入,
打印十六进制代码
实际:
##character setcol 00fe00:
将 00fe00 转换为 discord.color() 对象,
将对象转换为字符串,
将字符串保存在颜色配置变量中,
返回错误TypeError: Expected int parameter, received str instead,
函数终止
【问题讨论】:
-
完整的错误信息是什么?是您的
self.config.member呼叫失败还是嵌入?将颜色直接从转换器传递到嵌入应该可以工作,我不确定你为什么要将它更改为/从字符串 -
当我将原始用户输入放入 discord.Color() 时,它会抛出一个错误,指出它需要一个 int 或 discord.Color 对象,但收到的是一个字符串,这就是为什么我有所有的皈依者
-
在 red discord bot 社区服务器的帮助下,我得以解决。必须做一些魔法才能让所有变量都发挥得很好,发布更新的代码
标签: python discord discord.py discord.py-rewrite