简体   繁体   English

为什么我不能使用某些在嵌入的字母中包含字母的十六进制颜色?

[英]Why I can't use some of HEX-colors that include letters in my embed?

I'm trying to use HEX-color with letters (ex. 2c2f33) and it doesn't work, but If I use something as "3447003" it works. 我正在尝试使用带有字母(例如2c2f33)的十六进制颜色,但是它不起作用,但是如果我使用“ 3447003”这样的颜色,它会起作用。 So what should I do to make it work? 那么我应该怎么做才能使其正常工作呢?

message.channel.send({embed: {
      color: 2c2f33,
      fields: [
        { name: "Gaming Roles:", value: "<:gta:605106790534742057><@&587234726834733056>\n<:r6s:605106790677348372><@&587234959752822824>\n<:Fortnite:605106790580879361><@&587461980172976168>\n󠇰<:pubg:605106790690193428><@&587240268068159497>\n<:arma:605109711703900170><@&587238820890804224>\n<:division:605106790673416202><@&587239012909973517>", inline: true}
      ]

A color field within an embed object in Discord's Javascript API is of the type integer , meaning that it will only take a number as a value. Discord Javascript API中嵌入对象内的颜色字段的类型为integer ,这意味着它将仅将数字作为值。 The Hexadecimal number system is of base 16, meaning that the first 16 numbers are represented using 16 different symbols (0-9, AF). 十六进制数的基数为16,这意味着前16个数字使用16个不同的符号(0-9,AF)表示。 Because the color field can only take numeric characters and not alphanumeric characters, Hexadecimal doesn't work. 由于颜色字段只能接受数字字符,而不能包含字母数字字符,因此十六进制不起作用。 Thus, Discord's API team decided to use the vastly more common decimal (base 10) number system, the system we use every day with 10 symbols that are all numeric characters. 因此,Discord的API小组决定使用更为通用的十进制 (以10为底)数字系统,我们每天使用的系统中包含10个全为数字字符的符号。 This way, the input in your code will only be numbers. 这样,代码中的输入将仅是数字。

You have two options that I can think of: 您可以想到两种选择:

  1. Convert your colors yourself from Hexadecimal to Decimal, then use the result in your program instead of the hex code. 自己将颜色从十六进制转换为十进制,然后在程序中使用结果而不是十六进制代码。 The math needed to do this by hand is off-topic, but I can link you to this website to do it for you. 手动执行此操作所需的数学运算是不合时宜的,但我可以将您链接到此网站以为您完成。 This option can be somewhat tedious (even if you use a website) because of the copying and pasting. 由于复制和粘贴,此选项可能有些乏味(即使您使用的是网站)。

  2. put 0x before your hex code in the code. 在您的十六进制代码之前放置0x I'm not 100% sure this would work in JS; 我不是100%肯定这将在JS中工作; What it does is it marks the number as being hexadecimal, then converts it to decimal for you. 它所做的是将数字标记为十六进制,然后为您将其转换为十进制。

Resources: 资源:

https://discordapp.com/developers/docs/resources/channel#DOC_CHANNEL/embed-object https://discordapp.com/developers/docs/resources/channel#DOC_CHANNEL/embed-object

https://simple.wikipedia.org/wiki/Hexadecimal_numeral_system https://simple.wikipedia.org/wiki/Hexadecimal_numeral_system

Related Tags: , , 相关标签:

Use a string containing your hexadecimal value. 使用包含您的十六进制值的字符串

embed: {
  color: "2c2f33",
  fields: [...]
}

When creating a RichEmbed , the color property can be set to a ColorResolvable , so it can be any of the following: 创建RichEmbed时 ,可以将color属性设置为ColorResolvable ,因此可以是以下任意一种:

  • Hex Literal 十六进制字面量
  • Hex String 十六进制字符串
  • Number
  • RGB Array RGB阵列
  • See hyperlinked documentation page for a list of pre-defined strings. 请参阅超链接的文档页面以获取预定义字符串的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM