为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

皈依舞 2023-03-18 17:36:29
这是我的代码。我想知道是否有一种方法可以在用户不满足长度小于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.'); });
查看完整描述

1 回答

?
慕哥9229398

TA贡献1877条经验 获得超6个赞

你可以把它放在一个函数中,然后一遍又一遍地重复这个函数。


message.author.send(

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

);

const collecter = () => {

 message.channel

  .awaitMessages(

   (response) => response.author.id === message.author.id, // remove requirement from function

   {

    max: 1,

    time: 10000,

    errors: ['time'],

   }

  )

  .then((collected) => {

   if (collected.first().content.length < 200) {

    // add it in the callback

    message.channel.send('bla bla bla went wrong! Please try again');

    collector(); // repeat the function

   }

   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.');

  });

};


collector();


查看完整回答
反对 回复 2023-03-18
  • 1 回答
  • 0 关注
  • 128 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号