简体   繁体   English

如果我没有特定的页脚文本/img args,我该如何制作 my.setFooter,它只是 null?

[英]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 ,假设abany类型。 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.

相关问题 如何让我的页脚随着内容移动(使其具有响应性)? - How can I make my footer move with the content (make it responsive)? 如何使这个函数面向对象,以便我可以向我的对象添加一个新位置并且它可以在我的函数中工作? - How do I make this function object-oriented so that I can just add a new location to my object and it will work in my function? 当我的数组包含一个特定的单词时,我该如何做到这一点? - How do I make it so when my array includes a specific word a text input shows up? 如何使我的 web 页脚达到 100% 高度? - How can I make my web page footer in 100% height? 我想让我的购物车本地化,所以每次我刷新页面时,我的东西仍然需要在那里,但我只是找不到正确的方法来做到这一点 - i want to make my shoppingcart local so every time i refresh the page my stuff still needs to be in there but i just dont find the right way to do it 如何让我的脚本中心img in div - How can i make my script center img in div 如何在不干扰按钮和图像的情况下使我的文本位于图像下方? - How can I make my text just below the image without disturbing buttons and image? 我怎样才能使下划线文本只是一个点? - How I can make a underline text to be just a point? 我怎样才能从我的字符串中删除特定字符? - How can i trim just specific characters from my string? 如何使用 javascript 更改字符串的一部分中的文本? - How can I change the text in just a part of my string with javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM