bulkDelete method not working as intended












1














I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.



try {
let mod = message.guild.roles.find(role => role.name === "Mods");

if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');

if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");

if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');

message.channel.bulkDelete(args[0] + 1);
} catch (err) {
console.log(err)
}


As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.










share|improve this question





























    1














    I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.



    try {
    let mod = message.guild.roles.find(role => role.name === "Mods");

    if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');

    if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");

    if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');

    message.channel.bulkDelete(args[0] + 1);
    } catch (err) {
    console.log(err)
    }


    As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.










    share|improve this question



























      1












      1








      1







      I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.



      try {
      let mod = message.guild.roles.find(role => role.name === "Mods");

      if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');

      if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");

      if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');

      message.channel.bulkDelete(args[0] + 1);
      } catch (err) {
      console.log(err)
      }


      As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.










      share|improve this question















      I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.



      try {
      let mod = message.guild.roles.find(role => role.name === "Mods");

      if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');

      if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");

      if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');

      message.channel.bulkDelete(args[0] + 1);
      } catch (err) {
      console.log(err)
      }


      As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.







      javascript node.js discord discord.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 18:46









      Federico Grandi

      2,70021127




      2,70021127










      asked Nov 19 '18 at 18:27









      Adam KerikAdam Kerik

      5318




      5318
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Unfortunately You've not read official manual about bulkDelete method



          Otherwise You would know that it returns promise.



          also keep in mind this:




          Bulk delete given messages that are newer than two weeks.



          This is only available when using a bot account.






          So if Your account is bot account You can do it:



          message.channel
          .bulkDelete(args[0] + 1)
          .then(messages => console.log(`Bulk deleted ${messages.size} messages`))
          .catch(console.error);





          share|improve this answer





















          • So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
            – Adam Kerik
            Nov 19 '18 at 18:41










          • it does matter that You've to run that promise. Promise is special kind of class that has to be executed with then or using async/await sugar
            – num8er
            Nov 19 '18 at 18:42








          • 1




            Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
            – Adam Kerik
            Nov 19 '18 at 18:45











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380609%2fbulkdelete-method-not-working-as-intended%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Unfortunately You've not read official manual about bulkDelete method



          Otherwise You would know that it returns promise.



          also keep in mind this:




          Bulk delete given messages that are newer than two weeks.



          This is only available when using a bot account.






          So if Your account is bot account You can do it:



          message.channel
          .bulkDelete(args[0] + 1)
          .then(messages => console.log(`Bulk deleted ${messages.size} messages`))
          .catch(console.error);





          share|improve this answer





















          • So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
            – Adam Kerik
            Nov 19 '18 at 18:41










          • it does matter that You've to run that promise. Promise is special kind of class that has to be executed with then or using async/await sugar
            – num8er
            Nov 19 '18 at 18:42








          • 1




            Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
            – Adam Kerik
            Nov 19 '18 at 18:45
















          1














          Unfortunately You've not read official manual about bulkDelete method



          Otherwise You would know that it returns promise.



          also keep in mind this:




          Bulk delete given messages that are newer than two weeks.



          This is only available when using a bot account.






          So if Your account is bot account You can do it:



          message.channel
          .bulkDelete(args[0] + 1)
          .then(messages => console.log(`Bulk deleted ${messages.size} messages`))
          .catch(console.error);





          share|improve this answer





















          • So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
            – Adam Kerik
            Nov 19 '18 at 18:41










          • it does matter that You've to run that promise. Promise is special kind of class that has to be executed with then or using async/await sugar
            – num8er
            Nov 19 '18 at 18:42








          • 1




            Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
            – Adam Kerik
            Nov 19 '18 at 18:45














          1












          1








          1






          Unfortunately You've not read official manual about bulkDelete method



          Otherwise You would know that it returns promise.



          also keep in mind this:




          Bulk delete given messages that are newer than two weeks.



          This is only available when using a bot account.






          So if Your account is bot account You can do it:



          message.channel
          .bulkDelete(args[0] + 1)
          .then(messages => console.log(`Bulk deleted ${messages.size} messages`))
          .catch(console.error);





          share|improve this answer












          Unfortunately You've not read official manual about bulkDelete method



          Otherwise You would know that it returns promise.



          also keep in mind this:




          Bulk delete given messages that are newer than two weeks.



          This is only available when using a bot account.






          So if Your account is bot account You can do it:



          message.channel
          .bulkDelete(args[0] + 1)
          .then(messages => console.log(`Bulk deleted ${messages.size} messages`))
          .catch(console.error);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 18:36









          num8ernum8er

          11.4k21939




          11.4k21939












          • So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
            – Adam Kerik
            Nov 19 '18 at 18:41










          • it does matter that You've to run that promise. Promise is special kind of class that has to be executed with then or using async/await sugar
            – num8er
            Nov 19 '18 at 18:42








          • 1




            Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
            – Adam Kerik
            Nov 19 '18 at 18:45


















          • So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
            – Adam Kerik
            Nov 19 '18 at 18:41










          • it does matter that You've to run that promise. Promise is special kind of class that has to be executed with then or using async/await sugar
            – num8er
            Nov 19 '18 at 18:42








          • 1




            Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
            – Adam Kerik
            Nov 19 '18 at 18:45
















          So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
          – Adam Kerik
          Nov 19 '18 at 18:41




          So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
          – Adam Kerik
          Nov 19 '18 at 18:41












          it does matter that You've to run that promise. Promise is special kind of class that has to be executed with then or using async/await sugar
          – num8er
          Nov 19 '18 at 18:42






          it does matter that You've to run that promise. Promise is special kind of class that has to be executed with then or using async/await sugar
          – num8er
          Nov 19 '18 at 18:42






          1




          1




          Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
          – Adam Kerik
          Nov 19 '18 at 18:45




          Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
          – Adam Kerik
          Nov 19 '18 at 18:45


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380609%2fbulkdelete-method-not-working-as-intended%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          Npm cannot find a required file even through it is in the searched directory