等待私信回复discord.js
Await reply in private message discord.js
所以,这几乎可以按预期工作。我让机器人向在服务器的正确频道中使用正确命令的用户发送私人消息。我没有让配置文件创建消息阻塞服务器,而是让机器人私下创建配置文件。我 know/think 问题出在 message.channel.awaitMessages,因为它只能在执行命令的服务器上的原始频道中看到回复。
我不确定我应该用什么替换 message.channel.awaitMessages 以便它接收私人消息对话中的回复而不是服务器上的原始配置文件创建频道。
我还没有测试 sql 消息。我还没有测试过我拥有的东西,但我很确定它不会起作用。我希望将用户在私人消息中给出的回复插入(也许更新?)到我已经设置并正常工作的 mysql 数据库中。用户 ID 和用户名已放入此 table 中,其余与个人资料相关的问题目前为空。当他们回答这些问题时,可以填写这些字段 out/updated。欢迎任何ideas/suggestions!
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.');
});
});
}
提前感谢您的宝贵时间!
我不会用SQL所以,既然问题不是专门针对那个,就不要问我了。
当您使用 message.channel.awaitMessages
时,message
仍然是您在 module.exports.run
函数中传递的第一个,而不是来自 send()
的第一个。 send
解析后,它会传递一条新消息,您必须将其包含在放入 then
的函数的参数中:因此,您需要类似 .then(function() {})
的东西.then(function(new_message_sent_in_private) {})
这应该可以解决问题:
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.');
});
});
}
如果可行,请告诉我:)
所以,这几乎可以按预期工作。我让机器人向在服务器的正确频道中使用正确命令的用户发送私人消息。我没有让配置文件创建消息阻塞服务器,而是让机器人私下创建配置文件。我 know/think 问题出在 message.channel.awaitMessages,因为它只能在执行命令的服务器上的原始频道中看到回复。
我不确定我应该用什么替换 message.channel.awaitMessages 以便它接收私人消息对话中的回复而不是服务器上的原始配置文件创建频道。
我还没有测试 sql 消息。我还没有测试过我拥有的东西,但我很确定它不会起作用。我希望将用户在私人消息中给出的回复插入(也许更新?)到我已经设置并正常工作的 mysql 数据库中。用户 ID 和用户名已放入此 table 中,其余与个人资料相关的问题目前为空。当他们回答这些问题时,可以填写这些字段 out/updated。欢迎任何ideas/suggestions!
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.');
});
});
}
提前感谢您的宝贵时间!
我不会用SQL所以,既然问题不是专门针对那个,就不要问我了。
当您使用 message.channel.awaitMessages
时,message
仍然是您在 module.exports.run
函数中传递的第一个,而不是来自 send()
的第一个。 send
解析后,它会传递一条新消息,您必须将其包含在放入 then
的函数的参数中:因此,您需要类似 .then(function() {})
的东西.then(function(new_message_sent_in_private) {})
这应该可以解决问题:
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.');
});
});
}
如果可行,请告诉我:)