Search code examples
javascriptbotsdiscord.jsmessage

message is not defined, i dont get behind it


So i cant get behind it how i can define message, i already searched a lot and tried some things but it wont work. I am a beginner so i probably just forgot where or how I have to do it.

client.on("guildMemberAdd", async member => {
        try {
        await member.send(`Hello ${member}, welcome to the PotatoHost Server! 
I want to help you and so my question is: Do you want to buy a server or do you need more informations first? \n
A: I want to buy a server
B: I need more informations first \n
Please react to this message with A or B.`)
            .then(function (message) {
                message.react("🇦")
                message.react("🇧")
            });

            message.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '🇦' || reaction.emoji.name == '🇧'),
                { max: 1}).then(collected => {
                    if (collected.first().emoji.name == '🇦') {
                        message.reply('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.');
                        client.destroy();

                    }
                    else
                    message.reply('Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.');
                })

        } catch (err) {
            console.log(err)
        }
    })

 client.login(token);

Solution

  • I am not sure about it but why you are not moving message inside the message scope?

    client.on("guildMemberAdd", async member => {
            try {
            await member.send(`Hello ${member}, welcome to the PotatoHost Server! 
    I want to help you and so my question is: Do you want to buy a server or do you need more informations first? \n
    A: I want to buy a server
    B: I need more informations first \n
    Please react to this message with A or B.`)
                .then(function (message) {
                    message.react("🇦")
                    message.react("🇧")
                message.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '🇦' || reaction.emoji.name == '🇧'),
                    { max: 1}).then(collected => {
                        if (collected.first().emoji.name == '🇦') {
                            message.reply('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.');
                            client.destroy();
    
                        }
                        else
                        message.reply('Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.');
                    })
    
                });
    
    
            } catch (err) {
                console.log(err)
            }
        })
    
     client.login(token);