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 comes when I try to use another command 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 command is being used. Can commands 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 command, which is stored in a separate command 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" command 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!");
});
Answer from comments
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 command regardless of the channel type. If you want to allow some commands only in certain channels, you can do that either in the client.on("message")
or in the function of the command itself.