0

So pretty much whats going on is I made this line of code for my bot:

@client.command(pass_context=True)
async def weewoo(ctx):
        for _ in range(number_of_times):
            await client.say('example command 1')
            if client.wait_for_message(content='~patched'):
                await client.say('example command 2')
                break

And it works BUT when I run the bot and type the command it comes out like this:

example command 1
example command 2

And what I am trying to do is enter a command that starts spamming 'example command 1' and trying to end the spam with a command and it sending a message saying 'example command 2'. But instead it does that. If anyone could help that'd be dope.

1 Answer 1

1

You have to await the client.wait_for_message. It returns a message object. A better approach would be to create a global variable and set it to true when it loops, then false when the command patched is used. Hence stopping the loop.

checker = False

@client.command(pass_context=True)
async def weewoo(ctx):
    global checker
    checker = True

    for _ in range(number_of_times):
        await client.say('example command 1')
        if not checker:
            return await client.say('example command 2')


@client.command()
async def patched():
    global checker
    checker = False

However of course, the bot would only send 5 messages and then stops and then continues again. You can put a 1.2 second interval between the intervals of the spam.

@client.command(pass_context=True)
async def weewoo(ctx):
    global checker
    checker = True

    for _ in range(number_of_times):
        await client.say('example command 1')
        if not checker:
            return await client.say('example command 2')

        await asyncio.sleep(1.2)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much! I've been working on this for awhile
No problem :) if it was of use to you, you can mark the answer as "accepted" by clicking the check mark. @user8328934

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.