Umair Ahmed
Umair Ahmed

Reputation: 71

Discord code is running multiple times for no reason

So I have this piece of code which is running on a discord bot which should repeat what the user says after a command. It does this but repeats it another 7 times after making 8 total runs through that script. Can anyone spot why this might be happening?

Note: The code that actually runs starts from the elif but I put in everything just in case something prior was messing with it.

@Client.event 
async def on_message(message):
  if message.content == "s!ping":
    userID = message.author.id
    Client.send_message(message.channel, "<@%s>" % (userID))
  elif message.content.startswith == "s!say":
    args = message.content.split(" ")
    Client.send_message(message.channel, "%s" % (args[1:]))

Image to show test input and output

Upvotes: 5

Views: 1081

Answers (2)

Amjad Masad
Amjad Masad

Reputation: 4035

I'm the CEO of Repl.it. I think this might be a bug with scaling on our service where we might run multiple instances of your server. We'll have a fix for this soon. Meanwhile, I think some other Repl.it users had a fixe for this. Join us on our Discord, there are lots of bot developers there that can help you with this https://discord.gg/xa6S23

Upvotes: 2

asinggih
asinggih

Reputation: 26

In your code you're sending out a list. Try joining the list (which will return a string) after you split it, and send that. Something like this code below

elif message.content.startswith == "s!say":
    args = message.content.split(" ")
    out = " ".join(args[1:]) # concat the message without the "s!say"
    Client.send_message(message.channel, out)

Upvotes: 0

Related Questions