[英]How can i make my .setFooter so if i dont specific footer text/img args its just null?
How can i make my.setFooter the same as the rest of my embed?如何使 my.setFooter 与我嵌入的 rest 相同? To make it so if i dont specific footer text/img args its just null?要做到这一点,如果我没有特定的页脚文本/img 参数,它只是 null?
.setTitle( args[1] ? args[1] : null)
.setDescription( args[2] ? args[2] : null)
.setFooter({ text: args[3], iconURL: args[4] })
.setThumbnail( args[5] ? args[5] : null)
.setImage( args[6] ? args[6] : null)
.setColor( args[7] ? args[7] : null);
This is my current code, everything else works how i set it up however im not sure how to do that for.setFooter.这是我当前的代码,其他一切都按照我的设置方式工作,但我不确定如何为.setFooter 执行此操作。
You don't really need the ternary operator.你真的不需要三元运算符。 Just use args[1] || null
只需使用args[1] || null
args[1] || null
. args[1] || null
。 This expression resolves to either args[1]
, or, if that's a falsy value , null
.此表达式解析为args[1]
,或者,如果这是一个虚假值,则解析为null
。 For your EmbedBuilder.setFooter()
, you would do this:对于您的EmbedBuilder.setFooter()
,您可以这样做:
EmbedBuilder
// ...
.setFooter({
text: args[3] || null,
iconURL: args[4] || null
})
// ...
Here's a more detailed explanation of this:这是对此的更详细解释:
Take the expression a || b
取表达式a || b
a || b
, given that a
and b
are of type any
. a || b
,假设a
和b
是any
类型。 If a
is a falsy value , this returns b
.如果a
是假值,则返回b
。 Otherwise, it returns a
.否则,它返回a
.
This also works with functions, as shown in the following example:这也适用于函数,如以下示例所示:
function a() { return 0; }
function b() { return -2048; }
function c() { return 4096 }
a || b // Returns `-2048`
c || b // Returns `4096`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.