AirKetchup
AirKetchup

Reputation: 198

Bot executing the same command twice

I am making a discord bot with the rewrite, but when my command runs, it sends the message twice There is 100% no other calls to send that message, and it is only the 1st message(Hold on, I'm gathering the data), that is sent twice. Here is the command's code:

    @bot.command()
    async def testcmd(ctx):
      print("called")
      msgtemp = await ctx.message.channel.send("Hold on, I'm gathering the data")
      print("sent")
      time.sleep(3)
      await msgtemp.delete()
      with open("fileofthings.txt") as fl:
        await ctx.send(fl.read())

Upvotes: 3

Views: 6397

Answers (2)

Gaming with GreatAK
Gaming with GreatAK

Reputation: 21

Had the same issue and it literally drove me mad. The problem may be that either you are running the same bot file from multiple devices or you are running it multiple times with the same device. My problem was fixed by following this method:

  • Open Task Manager in your device
  • Click on 'More details'
  • In the processes tab, search for 'python 3.9 (or whatever version you are currently using)', and click on it and click 'End task'.

Hope this resolves your issue.

Upvotes: 0

Axisnix
Axisnix

Reputation: 2907

I had the same issue with my bot sending responses twice, does this happen with this particular command or it happens with other commands as well.

My theory is that you are running 2 versions of the bot meaning you get 2 messages. I developed a shutdown command in case this happens to me again

This is my code for a shutdown command if you need it.

@commands.command()
  async def shutdown(self,ctx):
    if ctx.message.author.id == OWNERID: #replace OWNERID with your user id
      print("shutdown")
      try:
        await self.bot.logout()
      except:
        print("EnvironmentError")
        self.bot.clear()
    else:
      await ctx.send("You do not own this bot!")

Upvotes: 5

Related Questions