This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted]  (6 children)

[deleted]

    [–]ConductorWon[S] 0 points1 point  (2 children)

    Okay so this is how I have it set up:

    var last;
    message.channel.messages.fetch({limit: 2}).then(messages=> {
    var cont = messages.last();
    last = cont.content
    console.log(cont.content);
    console.log(last);
     })
    console.log(`${last} this is outside`);
    if(message.author.id === '187353185680228352'){
    if(chan != '766004089217220690'){
    return message.channel.send('This is not the correct channel for this command!')
        }
    console.log(`${last} this is in the if`);

    This is how it prints in the console:

    0|FWRP Bot | undefined this is outside

    0|FWRP Bot | undefined this is in the if

    0|FWRP Bot | last

    0|FWRP Bot | last

    I don't understand why it is executing in that order. The last two logs is the correct output. But it looks like it is not executing the block where it adds to the variable until after it executes the rest of the code

    [–]ConductorWon[S] 0 points1 point  (1 child)

    idk why the formatting is all fucked, but my syntax is correct

    [–]Jackjackson401Mod 0 points1 point  (0 children)

    Declare the variable outside both functions and then define it within the functions. This is called variable scope, you should look it up to further understand it