1

I'm new to coding in python, and I'm having trouble with this code.

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if 'choose my pick' in message.content:
        channel = message.channel
        await channel.send('Que role tu ta?')

    def check(m):
        return m.content == 'top' or 'jg' or 'mid' or 'adc' or 'sup' and m.channel == channel

    role = await client.wait_for('message', check=check)
    sentence_start = random.choice(inu_exp)
    iten = random.choice(itens)

    if 'top' in role.content:
        champion = random.choice(top_champs)
        await channel.send(f'{sentence_start} {champion} de {iten}')
    await client.process_commands(message)

It works as I want to, when someone type 'choose my pick' it asks 'Que role tu ta', but it asks many times, and it also sends the answer await channel.send(f'{sentence_start} {champion} de {iten}') many times. Here's the output: https://prnt.sc/y1cucv I'm using python 3.8.6

1
  • Pretty sure you're running hidden python processes, open the task manager, look for those and kill them, you can also restart your pc Commented Feb 2, 2021 at 16:51

1 Answer 1

3

I have tested your code onto another bot and it only sent the message once! Make sure that there aren't multiple clients running at the same time! Another thing to make sure of is your internet ping as this could cause lag and result in having multiple messages! (Past Experience)

In addition, if your still having problems please send the entire code (without the token of course) because many variables are missing and I can't do anything without those variables. For example the inu_exp!

1
  • it happens to me a few minutes ago, having two different terminal emulator at a time: thank you for the hint Commented Sep 30 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.