我希望我的嵌入颜色设置在2种不同的颜色之间

发布于 2025-02-12 03:19:33 字数 317 浏览 1 评论 0原文

因此,目前,我有一个代码,该代码选择黄色将其设置为嵌入的颜色。

.setColor('Yellow')

这可以正常工作,并将嵌入的颜色设置为黄色。凭借我对JS的有限了解,我认为添加||是逻辑运算符,它将允许bot在黄色或其他颜色之间进行选择。因此,我将代码更改为:

.setColor('Yellow'||'red')

在测试此代码时,它不起作用。它只是将颜色保持在黄色。我尝试多次保存文件。我还允许机器人离线然后退休,无济于事。有人可以帮我吗?

So currently, I have a piece of code which chooses yellow to set as the colour of the embed.

.setColor('YELLOW')

This works fine and sets the colour of the embed to yellow. With my limited knowledge of js, I figured that adding || which is the logical OR operator, it would allow the bot to choose between either yellow or another colour. So I changed the code to this:

.setColor('YELLOW' || 'RED')

When I tested this code, it didn't work. It just kept the colour to yellow. I tried saving the file multiple times. I also allowed the bot to go offline and then retired it, to no avail. Could someone help me out, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱影子 2025-02-19 03:19:33

OR(||)操作员始终返回首先真实值yellow在您的情况下。

如果您只想在这两个之间进行选择,则可以将它们放入数组中并使用 math.random() 生成一个随机数。如果此数字小于0.5,则可以选择第一个数字,如果它更大,请选择第二个:

console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])

您可以这样更新代码:

.setColor(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])

The OR (||) operator always returns the first truthy value, YELLOW in your case.

If you only want to choose between those two, you can put them in an array and use Math.random() to generate a random number. If this number is less than 0.5, you can choose the first one, if it's larger, choose the second one:

console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])

You can update your code like this:

.setColor(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文