hansbi
hansbi

Reputation: 13

Discord.py bot sending messages multiple times

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

Upvotes: 1

Views: 713

Answers (1)

BlueFire02
BlueFire02

Reputation: 116

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!

Upvotes: 3

Related Questions