discord.py message getting sent multiple times, increases by 1 each time









up vote
1
down vote

favorite












Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:



if hour == 14:
await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
science = random.choice(sciences)
asyncio.sleep(0.5)
await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
asyncio.sleep(1)
await bot.send_message(message.channel, "you can take a break at 3:00")
while hour >= 14 and hour < 15:
msg = await bot.wait_for_message(timeout=3, author=message.author)
if msg:
await bot.delete_message(msg)
hour = int(time.strftime("%H"))


After the 4th time i type in #start it throws up an error saying:



discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message


Not sure what's wrong with the code or how I can stop it from happening. Help please?










share|improve this question

























    up vote
    1
    down vote

    favorite












    Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:



    if hour == 14:
    await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
    science = random.choice(sciences)
    asyncio.sleep(0.5)
    await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
    asyncio.sleep(1)
    await bot.send_message(message.channel, "you can take a break at 3:00")
    while hour >= 14 and hour < 15:
    msg = await bot.wait_for_message(timeout=3, author=message.author)
    if msg:
    await bot.delete_message(msg)
    hour = int(time.strftime("%H"))


    After the 4th time i type in #start it throws up an error saying:



    discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message


    Not sure what's wrong with the code or how I can stop it from happening. Help please?










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:



      if hour == 14:
      await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
      science = random.choice(sciences)
      asyncio.sleep(0.5)
      await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
      asyncio.sleep(1)
      await bot.send_message(message.channel, "you can take a break at 3:00")
      while hour >= 14 and hour < 15:
      msg = await bot.wait_for_message(timeout=3, author=message.author)
      if msg:
      await bot.delete_message(msg)
      hour = int(time.strftime("%H"))


      After the 4th time i type in #start it throws up an error saying:



      discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message


      Not sure what's wrong with the code or how I can stop it from happening. Help please?










      share|improve this question













      Really hard to word in a title. Basically I have a function called #start, which when called at a specific time will send a message on discord asking me to revise until (again) a specific time. But when I go back on discord, it turns out the message has been sent twice. So then I try doing the #start command and it sends the same message 3 times. If I type in #start again, it comes up 4 times. This is my code:



      if hour == 14:
      await bot.send_message(message.channel, "<@258621320898543616> Why don't you try some science revision now?")
      science = random.choice(sciences)
      asyncio.sleep(0.5)
      await bot.send_message(message.channel, "<@258621320898543616> lemme see, how about " +science+"? Look over some of that")
      asyncio.sleep(1)
      await bot.send_message(message.channel, "you can take a break at 3:00")
      while hour >= 14 and hour < 15:
      msg = await bot.wait_for_message(timeout=3, author=message.author)
      if msg:
      await bot.delete_message(msg)
      hour = int(time.strftime("%H"))


      After the 4th time i type in #start it throws up an error saying:



      discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message


      Not sure what's wrong with the code or how I can stop it from happening. Help please?







      python bots discord discord.py






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 14:30









      brandone

      255




      255






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Add a global value indicating whether or not the #start command is running.



          from discord.ext.commands import Bot

          bot = Bot(command_prefix='#')
          start_running = False

          @bot.event
          async def on_message(message):
          global start_running
          if message.content.startswith('#start'):
          if not start_running:
          start_running = True
          # do stuff
          start_running = False

          bot.run("token")





          share|improve this answer






















          • problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single if message.content.startswith('#start'): statement. And this if statement is inside a async def on_message() coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
            – brandone
            Nov 11 at 16:05











          • soo it's not really a command per se.
            – brandone
            Nov 11 at 16:07











          • and doing it that way prevents me from using anything to do with message
            – brandone
            Nov 11 at 16:22










          • is there any way to make it so the wait_for_message() uses a user ID to determine if a message is taken?
            – brandone
            Nov 11 at 16:25










          • @brandone You can easily do this with on_message, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
            – Patrick Haugh
            Nov 11 at 16:29










          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',
          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%2f53249712%2fdiscord-py-message-getting-sent-multiple-times-increases-by-1-each-time%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








          up vote
          1
          down vote













          Add a global value indicating whether or not the #start command is running.



          from discord.ext.commands import Bot

          bot = Bot(command_prefix='#')
          start_running = False

          @bot.event
          async def on_message(message):
          global start_running
          if message.content.startswith('#start'):
          if not start_running:
          start_running = True
          # do stuff
          start_running = False

          bot.run("token")





          share|improve this answer






















          • problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single if message.content.startswith('#start'): statement. And this if statement is inside a async def on_message() coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
            – brandone
            Nov 11 at 16:05











          • soo it's not really a command per se.
            – brandone
            Nov 11 at 16:07











          • and doing it that way prevents me from using anything to do with message
            – brandone
            Nov 11 at 16:22










          • is there any way to make it so the wait_for_message() uses a user ID to determine if a message is taken?
            – brandone
            Nov 11 at 16:25










          • @brandone You can easily do this with on_message, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
            – Patrick Haugh
            Nov 11 at 16:29














          up vote
          1
          down vote













          Add a global value indicating whether or not the #start command is running.



          from discord.ext.commands import Bot

          bot = Bot(command_prefix='#')
          start_running = False

          @bot.event
          async def on_message(message):
          global start_running
          if message.content.startswith('#start'):
          if not start_running:
          start_running = True
          # do stuff
          start_running = False

          bot.run("token")





          share|improve this answer






















          • problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single if message.content.startswith('#start'): statement. And this if statement is inside a async def on_message() coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
            – brandone
            Nov 11 at 16:05











          • soo it's not really a command per se.
            – brandone
            Nov 11 at 16:07











          • and doing it that way prevents me from using anything to do with message
            – brandone
            Nov 11 at 16:22










          • is there any way to make it so the wait_for_message() uses a user ID to determine if a message is taken?
            – brandone
            Nov 11 at 16:25










          • @brandone You can easily do this with on_message, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
            – Patrick Haugh
            Nov 11 at 16:29












          up vote
          1
          down vote










          up vote
          1
          down vote









          Add a global value indicating whether or not the #start command is running.



          from discord.ext.commands import Bot

          bot = Bot(command_prefix='#')
          start_running = False

          @bot.event
          async def on_message(message):
          global start_running
          if message.content.startswith('#start'):
          if not start_running:
          start_running = True
          # do stuff
          start_running = False

          bot.run("token")





          share|improve this answer














          Add a global value indicating whether or not the #start command is running.



          from discord.ext.commands import Bot

          bot = Bot(command_prefix='#')
          start_running = False

          @bot.event
          async def on_message(message):
          global start_running
          if message.content.startswith('#start'):
          if not start_running:
          start_running = True
          # do stuff
          start_running = False

          bot.run("token")






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 16:27

























          answered Nov 11 at 15:29









          Patrick Haugh

          26.3k82546




          26.3k82546











          • problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single if message.content.startswith('#start'): statement. And this if statement is inside a async def on_message() coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
            – brandone
            Nov 11 at 16:05











          • soo it's not really a command per se.
            – brandone
            Nov 11 at 16:07











          • and doing it that way prevents me from using anything to do with message
            – brandone
            Nov 11 at 16:22










          • is there any way to make it so the wait_for_message() uses a user ID to determine if a message is taken?
            – brandone
            Nov 11 at 16:25










          • @brandone You can easily do this with on_message, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
            – Patrick Haugh
            Nov 11 at 16:29
















          • problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single if message.content.startswith('#start'): statement. And this if statement is inside a async def on_message() coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
            – brandone
            Nov 11 at 16:05











          • soo it's not really a command per se.
            – brandone
            Nov 11 at 16:07











          • and doing it that way prevents me from using anything to do with message
            – brandone
            Nov 11 at 16:22










          • is there any way to make it so the wait_for_message() uses a user ID to determine if a message is taken?
            – brandone
            Nov 11 at 16:25










          • @brandone You can easily do this with on_message, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
            – Patrick Haugh
            Nov 11 at 16:29















          problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single if message.content.startswith('#start'): statement. And this if statement is inside a async def on_message() coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
          – brandone
          Nov 11 at 16:05





          problem is that the whole code i typed (along with many other while loops and if statements for different times throughout the day) is inside a single if message.content.startswith('#start'): statement. And this if statement is inside a async def on_message() coroutine. I did this so If i were to type in #start at anytime throughout the day, it would reply with whatever task is set for that time
          – brandone
          Nov 11 at 16:05













          soo it's not really a command per se.
          – brandone
          Nov 11 at 16:07





          soo it's not really a command per se.
          – brandone
          Nov 11 at 16:07













          and doing it that way prevents me from using anything to do with message
          – brandone
          Nov 11 at 16:22




          and doing it that way prevents me from using anything to do with message
          – brandone
          Nov 11 at 16:22












          is there any way to make it so the wait_for_message() uses a user ID to determine if a message is taken?
          – brandone
          Nov 11 at 16:25




          is there any way to make it so the wait_for_message() uses a user ID to determine if a message is taken?
          – brandone
          Nov 11 at 16:25












          @brandone You can easily do this with on_message, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
          – Patrick Haugh
          Nov 11 at 16:29




          @brandone You can easily do this with on_message, see my example above. If the command is just supposed to respond with the task for that time, why is there a loop at all?
          – Patrick Haugh
          Nov 11 at 16:29

















          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%2f53249712%2fdiscord-py-message-getting-sent-multiple-times-increases-by-1-each-time%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

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線