javascript - Private message commands in discord - Stack Overflow

I am making an RP profile creation setup for a discord bot using javascript. I have the conversation st

I am making an RP profile creation setup for a discord bot using javascript. I have the conversation starting in a channel and moving to private messaging with the bot. The first question gets asked and the reply from the user is stored in a database. That is working fine.

What seems to be the problem es when I try to use another mand inside a private message with the bot to move to the next step of the RP profile creation. It doesn't seem to register the mand is being used. Can mands even be used in private messaging with a bot?

I used the same code as the first question that worked, changed what needed to be, but nothing that should have broken the code. It just looks to not even see the second mand, which is stored in a separate mand file. How would I do this?

module.exports.run = async (bot, message, args) => {
message.author.send(` SECOND QUESTION, **What is the age of your Brawler or Character?**`)
  .then((newmsg) => { //Now newmsg is the message you send to the bot
    newmsg.channel.awaitMessages(response => response.content, {
      max: 1,
      time: 300000,
      errors: ['time'],
    }).then((collected) => {
      newmsg.channel.send(`Your brawler's age is: **${collected.first().content}**

      If you are okay with this age, type !profilegender to continue the profile creation process!

      If you would like to edit your age, please type !profileage`)
        con.query(`UPDATE profile SET age = '${collected.first().content}' WHERE id = ${message.author.id}`);
        console.log("1 record updated!")
    }).catch(() => {
      newmsg.channel.send('Please submit an age for your character. To restart Profile creation, please type "!profilecreate" mand in Profile Creation channel on the server.');
    });
  });
}

I am making an RP profile creation setup for a discord bot using javascript. I have the conversation starting in a channel and moving to private messaging with the bot. The first question gets asked and the reply from the user is stored in a database. That is working fine.

What seems to be the problem es when I try to use another mand inside a private message with the bot to move to the next step of the RP profile creation. It doesn't seem to register the mand is being used. Can mands even be used in private messaging with a bot?

I used the same code as the first question that worked, changed what needed to be, but nothing that should have broken the code. It just looks to not even see the second mand, which is stored in a separate mand file. How would I do this?

module.exports.run = async (bot, message, args) => {
message.author.send(` SECOND QUESTION, **What is the age of your Brawler or Character?**`)
  .then((newmsg) => { //Now newmsg is the message you send to the bot
    newmsg.channel.awaitMessages(response => response.content, {
      max: 1,
      time: 300000,
      errors: ['time'],
    }).then((collected) => {
      newmsg.channel.send(`Your brawler's age is: **${collected.first().content}**

      If you are okay with this age, type !profilegender to continue the profile creation process!

      If you would like to edit your age, please type !profileage`)
        con.query(`UPDATE profile SET age = '${collected.first().content}' WHERE id = ${message.author.id}`);
        console.log("1 record updated!")
    }).catch(() => {
      newmsg.channel.send('Please submit an age for your character. To restart Profile creation, please type "!profilecreate" mand in Profile Creation channel on the server.');
    });
  });
}

Thanks in advance for your time!

EDIT: This is part of the code that is the bot/client is listening for on message.

bot.on(`message`, async message => {
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  con.query(`SELECT * FROM profile WHERE id = '${message.author.id}'`, (err, rows) => {
    if(err) throw err;

    var sql;

    if(rows.length < 1) {
      var sql = (`INSERT INTO profile (id, username) VALUES (${message.author.id}, '${message.author.tag}')`);
    } else {
      var sql = (`UPDATE profile SET username = '${message.author.tag}' WHERE id = ${message.author.id}`);
    };

    //con.query(sql, console.log);
    //if (err) throw err;
    //console.log("1 record inserted!");
  });

Share Improve this question edited Jul 6, 2018 at 21:26 Zarvix asked Jul 6, 2018 at 11:35 ZarvixZarvix 1194 silver badges17 bronze badges 5
  • Are you sure that inside of your client.on("message") there is nothing that can prevent the bot from recognizing the mand (maybe something that checks for the prefix, or for a specific channel, or stuff like that...). Could you post that part of your code? Anyway, there's no problem in using mands via DM, but if your code relies only on TextChannels (instead of DMChannels) it may cause some issues (usually it's easily fixable) – Federico Grandi Commented Jul 6, 2018 at 19:20
  • That might be the issue. I didn't even consider that. I updated the OP with that part of the code. It does mention the channel type with a return after, so it doesn't seem like it awaits anything in DM on message when it es to mands. I am unsure how to fix that though. Simply remove the line mentioning "dm" as the message type? – Zarvix Commented Jul 6, 2018 at 21:25
  • Yep, that line tells the bot to exit the function if the channel is a DM. Keep in mind that if you remove that the bot will allow every mand to be executed via DM. If that's fine for you, you can just remove that. If you want only some mands to be used via DM, you may want to add an if check that returns if the channel is a DM && the mand is not allowed – Federico Grandi Commented Jul 7, 2018 at 9:05
  • 1 I specified that it needed to be in a certain channel for a couple of my other mands, so that shouldn't be an issue. The private message mands will be very few and all the other mands will be specified to certain channels in the server, so it shouldn't be much of a hassle to specify this for my needs. Thanks so much. If you want to post the gist of these ments as an answer so I can mark it as answered, that would be great. – Zarvix Commented Jul 7, 2018 at 11:17
  • Perfect! I just added an answer – Federico Grandi Commented Jul 7, 2018 at 12:17
Add a ment  | 

1 Answer 1

Reset to default 4

Answer from ments

Inside of your client.on("message") there's an if check that exits the function if the channel is a DMChannel

if(message.channel.type === "dm") return;

To avoid that, simply remove this line: in this way, the bot will execute the mand regardless of the channel type. If you want to allow some mands only in certain channels, you can do that either in the client.on("message") or in the function of the mand itself.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744787903a4593739.html

相关推荐

  • javascript - Private message commands in discord - Stack Overflow

    I am making an RP profile creation setup for a discord bot using javascript. I have the conversation st

    6小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信