【发布时间】:2021-02-04 16:52:26
【问题描述】:
我是不和谐的新手,并试图制作一个机器人,当用户收到命令时,它会回复用户,其中用户和机器人之间的消息将只对使用该命令的用户可见。我不知道该怎么做。这是我的以下代码源:
if (message.author.bot) return;
const filter = m => m.author.id === message.author.id;
message.reply("Enter your email Id please? you have some time of 100 seconds")
.then(msg => msg.delete(10000)) // so the message will delete after the time is up (10 seconds)
.catch(err => {}) // if the bot hasnt got perms to delete the message, it will ignore the error
message.channel.awaitMessages(filter, {
max: 1, // do NOT change this
time: 10000, // this is the time in MS you want it to last. (There are 1000 MS in 1 second)
errors: ['time'] // this ensures the only error is "time"
}).then(async(collected) => { // collected is a collection so we use collected.first().content
if (collected.first().content.toLowerCase() == 'cancel') { // .toLowerCase() converts the user input to lower case, so if they type "CaNcEl" it will still be read as "cancel" and the if statement will run
message.reply(":sob: The command has been cancelled.") // what to do if the user repleis "cancel"
}
email = collected.first().content; // finally send the collected message content to the message channel
if(email == emailregistered){
console.log(email);
message.reply("Check your DM please!");
}else{
message.reply("Sorry You are not authorized! Please contact team to get access to the channel!");
}
}).catch(() => {
message.reply("You took too long!")
})
}else{
message.reply("Channel Name does not exist, Try contacting Dev");
}
}
【问题讨论】:
标签: javascript node.js discord discord.js bots