不和谐中的私人消息命令
我正在使用javascript为discord bot制作RP配置文件创建设置 . 我在一个 Channels 开始谈话,然后转向使用机器人的私人消息 . 第一个问题被询问,用户的回复存储在数据库中 . 这工作正常 .
当我尝试在私人消息中使用另一个命令与机器人移动到RP配置文件创建的下一步时,似乎问题出现了 . 它似乎没有注册正在使用的命令 . 甚至可以在机器人的私人消息中使用命令吗?
我使用了与第一个有效的代码相同的代码,改变了所需的内容,但没有任何代码可以破坏代码 . 它只是看起来甚至没有看到第二个命令,它存储在一个单独的命令文件中 . 我该怎么做?
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.');
});
});
}
在此先感谢您的时间!
编辑:这是机器人/客户端正在侦听消息的代码的一部分 .
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!");
});
2 years ago
回答评论
你的
client.on("message")
里面有if检查,如果 Channels 是DMChannel则退出该功能为避免这种情况,只需删除此行:这样,无论通道类型如何,机器人都将执行命令 . 如果只想在某些通道中允许某些命令,可以在
client.on("message")
或命令本身的功能中执行此操作 .