我正在尝试使用节点js创建一个不和谐的机器人,并且我正在尝试获取用户名作为响应,并希望在用户输入其用户名后发送感谢信息。但是,这两个消息,询问用户名的文本以及同时发送给您的感谢信都会有所帮助。
module.exports = {
name: 'create',
description: "help page",
async pls(bot,message,args){
if(!args[2]){
message.channel.send('Server nickname was not passed');
return;
}
var details = {nickname:'',username:'',pass:'',ip:''};
details.nickname = args[2];
message.channel.send('Please check your private messages');
await message.author.send('Enter your username (PLS enter in 30 seconds)')
.then((newmsg) => {
newmsg.channel.awaitMessages(response => response.content, {
max: 1,
time: 15000,
errors: ['time'],
})
.then((collected) => {
details.username = collected.first().content;
console.log(details);
})
.catch(() => {
newmsg.channel.send('time ran out');
});
})
;
await message.channel.send('thanks');
}
}
答案 0 :(得分:-1)
第一件事是,您不必在同一行中使用
//This is the Kill Process Message, You can Ignore it!
static void MSG() //This is the Process Killed Message... You can Ignore it!!
{
Console.Title = "MSG"; Console.WindowHeight = 5; Console.WindowWidth = 32;
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\n////////////////////////////////\r\n >> Process Killed!! <<\r\n////////////////////////////////"); Console.ReadKey();
}
//Put This Code inside Main Program Method!!
foreach (System.Diagnostics.Process pr in System.Diagnostics.Process.GetProcesses())
{
if ((pr.ProcessName.IndexOf("word", StringComparison.OrdinalIgnoreCase) >= 0) == true) //Change "word" to your process name!
{
pr.Kill(); MSG();
}
}
和await
。两者都是用于返回Promise的函数的表示法,并且都告诉代码等待该Promise回来。然后,如果无论出现哪种情况都希望出现“谢谢”,则应使用then
,它仅在try或catch块出现后才运行。
也就是说,它应该看起来像这样:
finally