1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to use two ifs?

Discussion in 'JavaScript' started by Divvy, Oct 2, 2020.

  1. #1
    Hello guys,

    I'm working on a custom bot for Discord and I need some help.
    I have the following code:

    if(command === 'sino') {
    if (msg.channel.id === '761500739842506774') {
    msg.react(":thumbsup:")
    msg.channel.send("", {
    files: ["https://image.png"], });
    }}
    Code (markup):
    I think I'm doing something wrong with the if.
    What I want is to use the command !sino only on a specific channel.
    SEMrush
    I also have tried this but without success:

    if(command === 'sino') {
    msg.channel.id === '761500739842506774' {
    msg.react(":thumbsup:")
    msg.channel.send("", {
    files: ["https://image.png"], });
    }}
    Code (markup):
    Can someone please help me? :)

    Thank you!
     
    Divvy, Oct 2, 2020 IP
    SEMrush
  2. Divvy

    Divvy Well-Known Member

    Messages:
    727
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    It seems that the first code is now working, thank you anyway guys :)
     
    Divvy, Oct 2, 2020 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    6,717
    Likes Received:
    1,469
    Best Answers:
    25
    Trophy Points:
    425
    #3
    Did you try &&

    if(command === 'sino' && msg.channel.id === '761500739842506774') {
    msg.react(":thumbsup:")
    msg.channel.send("", {
    files: ["https://image.png"], });
    }
    Code (markup):
     
    qwikad.com, Oct 2, 2020 IP
    JEET likes this.
  4. JEET

    JEET Notable Member

    Messages:
    3,626
    Likes Received:
    457
    Best Answers:
    19
    Trophy Points:
    235
    #4
    I think this part is the problem.
    if (msg.channel.id === '761500739842506774' )

    You are using a strict equality check.
    I am thinking "id" is holding an integer,
    but '761500739842506774' is a string,
    so comparison is failing the equality check.

    Try one of these:
    if (msg.channel.id === 761500739842506774 )
    or this:
    if (msg.channel.id == '761500739842506774' )
     
    JEET, Oct 2, 2020 IP
    Efetobor Agbontaen likes this.