首页 > 解决方案 > 机器人是否可以为消息随机化 2 种颜色?

问题描述

我在我的嵌入中使用十进制颜色 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`,
      },
    },
  });

标签: javascriptnode.jsdiscord.jsbots

解决方案


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

// 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

推荐阅读