如何提示用户再次尝试输入

这是我的代码。我想知道是否有一种方法可以在用户不满足长度小于200个字符的要求时提示用户再次尝试输入标题。谢谢你的帮助!


message.author.send(

 'Lets get to work!\nPlease enter the title of your event. (Must be shorter than 200 characters)'

);

message.channel

 .awaitMessages(

  (response) =>

   response.author.id === message.author.id && response.content.length < 200,

  {

   max: 1,

   time: 10000,

   errors: ['time'],

  }

 )

 .then((collected) => {

  message.author.send(`I collected the message : ${collected.first().content}`);

  let title = collected.first().content;

 })

 .catch(() => {

  message.author.send('No message collected after 10 seconds.');

 });


皈依舞
浏览 130回答 1
1回答

慕哥9229398

你可以把它放在一个函数中,然后一遍又一遍地重复这个函数。message.author.send(&nbsp;'Lets get to work!\nPlease enter the title of your event. (Must be shorter than 200 characters)');const collecter = () => {&nbsp;message.channel&nbsp; .awaitMessages(&nbsp; &nbsp;(response) => response.author.id === message.author.id, // remove requirement from function&nbsp; &nbsp;{&nbsp; &nbsp; max: 1,&nbsp; &nbsp; time: 10000,&nbsp; &nbsp; errors: ['time'],&nbsp; &nbsp;}&nbsp; )&nbsp; .then((collected) => {&nbsp; &nbsp;if (collected.first().content.length < 200) {&nbsp; &nbsp; // add it in the callback&nbsp; &nbsp; message.channel.send('bla bla bla went wrong! Please try again');&nbsp; &nbsp; collector(); // repeat the function&nbsp; &nbsp;}&nbsp; &nbsp;message.author.send(&nbsp; &nbsp; `I collected the message : ${collected.first().content}`&nbsp; &nbsp;);&nbsp; &nbsp;let title = collected.first().content;&nbsp; })&nbsp; .catch(() => {&nbsp; &nbsp;message.author.send('No message collected after 10 seconds.');&nbsp; });};collector();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript