admin管理员组

文章数量:1392007

I'm trying to make my bot to wait for a direct message in this case some name and write it back to same user in direct message in this case me.

I try to use message.author.awaitMessages but console return:

TypeError: message.author.awaitResponse is not a function

message.author.send('Write your Name')
      .then(function(){
        message.channel.awaitMessages(response => message.content, {
          max: 1,
          time: 300000000,
          errors: ['time'],
        })
        .then((collected) => {
            message.author.send(`Your Name is: ${collected.first().content}`);
          })
          .catch(function(){
            message.channel.send('You didnt write your name');
          });
      });
  }

I'm trying to make my bot to wait for a direct message in this case some name and write it back to same user in direct message in this case me.

I try to use message.author.awaitMessages but console return:

TypeError: message.author.awaitResponse is not a function

message.author.send('Write your Name')
      .then(function(){
        message.channel.awaitMessages(response => message.content, {
          max: 1,
          time: 300000000,
          errors: ['time'],
        })
        .then((collected) => {
            message.author.send(`Your Name is: ${collected.first().content}`);
          })
          .catch(function(){
            message.channel.send('You didnt write your name');
          });
      });
  }
Share Improve this question asked Dec 8, 2017 at 21:43 Philip ScotPhilip Scot 3012 gold badges3 silver badges12 bronze badges 1
  • While calling the message.author.send can you confirm that message is definately the variable and it's not msg? Discord.js hello world uses client.on('message', msg) => { . In your case i think you need to change the msg here to message – Dan Ruxton Commented Dec 30, 2017 at 16:23
Add a ment  | 

3 Answers 3

Reset to default 1

Try message.author.dmChannel.awaitMessages

Check more info in the documentation https://discord.js/#/docs/main/stable/class/User?scrollTo=dmChannel

The Message class has the property author, which is of the type User class (as seen in the docs here), and the User class does not have the function awaitResponse(...), which is why you are seeing that error. See documentation of the User class here.

I would remend using message.channel.awaitMessages and checking the messages' .author property if you are checking for responses from a specific person.

message.author is from the User class which does not contain the awaitResponse() function. Use message.member (returns a GuildMember) instead of message.author

本文标签: javascriptAwait message from user in Direct Message Discord jsStack Overflow