【问题标题】:message is not defined, i dont get behind it消息未定义,我不支持它
【发布时间】:2020-07-29 14:48:44
【问题描述】:

所以我无法理解如何定义消息,我已经搜索了很多并尝试了一些东西,但它不会工作。我是初学者,所以我可能只是忘记了我必须在哪里或如何做。

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);

【问题讨论】:

    标签: javascript bots discord.js message


    【解决方案1】:

    我不确定,但为什么你不在消息范围内移动消息?

    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);
    

    【讨论】:

      【解决方案2】:

      message 仅在您的第一个 .then 函数的回调中定义。在不再定义它之后,您再次调用了message。将所有调用转移到 .then 内的消息以解决此问题。

      .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>.');
          })
      });
      
      

      您可能想阅读范围:https://www.w3schools.com/js/js_scope.asp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-17
        • 2021-04-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-07
        相关资源
        最近更新 更多