JavaScript等待函数错误(discord.js shell.js)
我是Node.js新手,我想在执行命令(使用shelljs)之前发送一条消息(使用discord.js)。问题是,我的消息是在命令执行之后发送的,我希望它在执行之前发送。谢谢你的帮助JavaScript等待函数错误(discord.js shell.js),javascript,node.js,Javascript,Node.js,我是Node.js新手,我想在执行命令(使用shelljs)之前发送一条消息(使用discord.js)。问题是,我的消息是在命令执行之后发送的,我希望它在执行之前发送。谢谢你的帮助 //Send message first message.channel.send('Starting Server...'); //Then run these commands shell.cd('/home/pi/...'); shell.exec('exec java ...'); message.ch
//Send message first
message.channel.send('Starting Server...');
//Then run these commands
shell.cd('/home/pi/...');
shell.exec('exec java ...');
message.channel.send('Starting Server…')
返回一个承诺,表示您可以使用等待
:
const sendMessage = async ()=>{
await message.channel.send('Starting Server...');
//Then run these commands
shell.cd('/home/pi/...');
shell.exec('exec java ...');
}
sendMessage()
或
message.channel.send('Starting Server…')
返回一个承诺,表示您可以使用等待
:
const sendMessage = async ()=>{
await message.channel.send('Starting Server...');
//Then run these commands
shell.cd('/home/pi/...');
shell.exec('exec java ...');
}
sendMessage()
或
您还应该将
try/catch
块与wait或一起使用。然后().catch()
,对于错误处理,您还应该将try/catch
块与wait或一起使用。然后().catch()
,用于错误处理