Await reply in private message discord.js

Zarvix

So, this works ALMOST as intended. I have the bot private messaging the user who uses the correct command in the correct channel of the server. Instead of clogging up the server with profile creation messages, I have the bot do profile creation privately. I know/think the problem is with the message.channel.awaitMessages, because it only sees the replies in the original channel on the server where the command was put into place.

I am not sure what I should replace the message.channel.awaitMessages with in order for it to pick up on the reply in the private message conversation rather than the original profile creation channel on the server.

I have not tested the sql message yet. I haven't tested what I have but I am pretty sure it won't work. I want the reply that is given by the user in the private message to be inserted (updated maybe?) into a mysql database I have already set up and properly got working. The users ID and username has been put into this table with the rest of the profile related questions being null at this moment. As they reply to these questions, those fields can be filled out/updated. Any ideas/suggestions are welcome!

module.exports.run = async (bot, message, args) => {
if(message.channel.id === '460633878244229120') return message.author.send(`Greetings, ${message.author.username}! FIRST QUESTION, **What is the name of your Brawler or Character?**`)
  .then(function(){
    message.channel.awaitMessages(response => message.content, {
      max: 1,
      time: 5000,
      errors: ['time'],
    })
    .then((collected) => {
        message.author.send(`Your Name is: ${collected.first().content}`);
        var sql = (`UPDATE profile SET name = '${message.content}' WHERE id = ${message.author.id}`);
      })
      .catch(function(){
        message.author.send('Please submit a name for your character. To restart Profile creation, please type "!profilecreate" command in Profile Creation channel on the server.');
      });
    });
  }

Thanks in advance for your time!

Federico Grandi

I don't use SQL so, since the question is not specifically on that, don't ask me.

When you're using message.channel.awaitMessages, message is still the first one that you passed in the module.exports.run function, not the one that comes from send(). When send is resolved, it passes a new message, that you have to include in the arguments of the function you put inside then: so, instead of .then(function() {}) you'll need something like .then(function(new_message_sent_in_private) {})

This should fix the problem:

module.exports.run = async (bot, message, args) => {
if(message.channel.id === '460633878244229120') return message.author.send(`Greetings, ${message.author.username}! FIRST QUESTION, **What is the name of your Brawler or Character?**`)
  .then((newmsg) => { //Now newmsg is the message you sent
    newmsg.channel.awaitMessages(response => response.content, {
      max: 1,
      time: 5000,
      errors: ['time'],
    }).then((collected) => {
      newmsg.channel.send(`Your Name is: ${collected.first().content}`);
      var sql = (`UPDATE profile SET name = '${message.content}' WHERE id = ${message.author.id}`);
    }).catch(() => {
      newmsg.channel.send('Please submit a name for your character. To restart Profile creation, please type "!profilecreate" command in Profile Creation channel on the server.');
    });
  });
}

Let me now if that worked :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make discord bot wait for reply for 5 minutes and then send a message? Using discord js

From Dev

Discord JS, reply to certain user ID

From Dev

Php Private Message reply only functioning on the last row?

From Dev

How to make my Bot Private Message the user who has been kicked by the bot ? (Discord.js)

From Dev

Use Discord API to send a private message given a user ID

From Dev

Twillio reply to message

From Dev

Welcome message embed Discord.js

From Dev

How to send message with discord.js with ID

From Dev

Discord js using message id in Embed

From Dev

Discord.js How to mention message author?

From Dev

Discord.JS Send message to tagged user

From Dev

Send a message if there is a role Discord.js

From Dev

Discord.js -- make presenceUpdate send a message

From Dev

Sending a message to a server and printing the reply

From Dev

Freeradius: No reply message for Failed Authentications

From Dev

Send private message using Node.js and Socket.io

From Dev

How to send private message to member in on_member_join() discord.py?

From Dev

how to pull message data from discord.js?

From Dev

How do I send a message to a specific channel in discord.js?

From Dev

Get last message from text channel with discord.js

From Dev

Discord js delete if message has many uppercase letter

From Dev

Check if a user can send message in a specific channel discord.js

From Dev

Discord.js message.embeds[0] not outputting anything;

From Dev

Discord.JS TypeError: message.author.hasPermission is not a function

From Dev

Can't store fetched message in a variable - Discord js

From Dev

Discord.JS getting all attachments from a message

From Dev

Line Separator/Break in Discord.js Embed Message

From Dev

Create a welcome message in the discord bot in js when a new member enters

From Dev

message.channel.send not working discord.js

Related Related

  1. 1

    How to make discord bot wait for reply for 5 minutes and then send a message? Using discord js

  2. 2

    Discord JS, reply to certain user ID

  3. 3

    Php Private Message reply only functioning on the last row?

  4. 4

    How to make my Bot Private Message the user who has been kicked by the bot ? (Discord.js)

  5. 5

    Use Discord API to send a private message given a user ID

  6. 6

    Twillio reply to message

  7. 7

    Welcome message embed Discord.js

  8. 8

    How to send message with discord.js with ID

  9. 9

    Discord js using message id in Embed

  10. 10

    Discord.js How to mention message author?

  11. 11

    Discord.JS Send message to tagged user

  12. 12

    Send a message if there is a role Discord.js

  13. 13

    Discord.js -- make presenceUpdate send a message

  14. 14

    Sending a message to a server and printing the reply

  15. 15

    Freeradius: No reply message for Failed Authentications

  16. 16

    Send private message using Node.js and Socket.io

  17. 17

    How to send private message to member in on_member_join() discord.py?

  18. 18

    how to pull message data from discord.js?

  19. 19

    How do I send a message to a specific channel in discord.js?

  20. 20

    Get last message from text channel with discord.js

  21. 21

    Discord js delete if message has many uppercase letter

  22. 22

    Check if a user can send message in a specific channel discord.js

  23. 23

    Discord.js message.embeds[0] not outputting anything;

  24. 24

    Discord.JS TypeError: message.author.hasPermission is not a function

  25. 25

    Can't store fetched message in a variable - Discord js

  26. 26

    Discord.JS getting all attachments from a message

  27. 27

    Line Separator/Break in Discord.js Embed Message

  28. 28

    Create a welcome message in the discord bot in js when a new member enters

  29. 29

    message.channel.send not working discord.js

HotTag

Archive