我希望我的嵌入颜色设置在2种不同的颜色之间
因此,目前,我有一个代码,该代码选择黄色将其设置为嵌入的颜色。
.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OR(
||
)操作员始终返回首先真实值,yellow
在您的情况下。如果您只想在这两个之间进行选择,则可以将它们放入数组中并使用
math.random()
生成一个随机数。如果此数字小于0.5
,则可以选择第一个数字,如果它更大,请选择第二个:您可以这样更新代码:
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 than0.5
, you can choose the first one, if it's larger, choose the second one:You can update your code like this: