【问题标题】:Is it possible for the bot to randomize 2 colors for a message?机器人是否可以为消息随机化 2 种颜色?
【发布时间】:2020-12-23 17:26:40
【问题描述】:

我在我的嵌入中使用十进制颜色 6275760,但我希望他也使用 16777201,当他发送嵌入时,他使用这两种颜色之一发送它

if (!args.length)
  return message.channel.send({
    embed: {
      color: 6275760,
      description: `<:FubukiX:749212433951883264> | ${message.author}, You need to put a message.`,
      footer: {
        text: `   | Exemple: !say hello`,
      },
    },
  });

【问题讨论】:

  • color: Math.random() &lt; 0.5 ? 6275760 : 16777201,
  • 只是一个旁注,我会高度建议将这些数字放在十六进制中。 color: 0x5fc2b0 作为 RGB 值比十进制等效值更容易理解。

标签: javascript node.js discord.js bots


【解决方案1】:

你可以,你需要做的就是添加这个。

// Array of all the colors you want to be randomized, add as much as you want.
const colorArray = [16777201, 6275760];
// Randomizing a number within the length of colorArray
const rand = Math.floor(Math.random() * colorArray.length);
// Defining the color by picking a random color from the colorArray
const color = colorArray[rand];
if (!args.length)
 return message.channel.send({
  embed: {
   color: color,
   description: `<:FubukiX:749212433951883264> | ${message.author}, You need to put a message.`,
   footer: {
    text: `   | Exemple: !say hello`,
   },
  },
 }); // Define color as `color` which is the randomized color we defined above

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 2017-11-20
    • 2021-08-19
    • 2019-04-24
    • 2021-07-12
    • 1970-01-01
    • 2019-06-13
    • 2018-06-17
    • 2021-07-19
    相关资源
    最近更新 更多