在结束命令之前,如何使命令循环一定次数?

时间:2020-08-30 04:03:59

标签: python discord discord.py

使用以下代码,我希望使其在结束之前循环2次,以防止聊天中出现垃圾邮件。

@Test
public void testMultiThread()  {
    
    Thread[] threads = new Thread[1];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(this::testTransaction);
        threads[i].start();
    }

    // wait thread completion
    for (Thread th : threads) {
        th.join();
    }

}

我想用这段代码做到这一点-

谢谢!

1 个答案:

答案 0 :(得分:1)

更新

# use a counter to track how many times you run the while loop
loop_counter = 0
while answer.lower() != "proceed" and answer.lower() != "return": 
    loop_counter += 1
    if loop_counter >=2:
    # break out of the loop if reach a threshold.
    # send out the message before break out of the loop.
        await ctx.send("The loop has ended.") 
        break
    await ctx.send("Only enter 'proceed' or 'return'!") 
    await ctx.send('''Are you sure you want to nuke this channel? This will completely erase all messages from it! type proceed to continue, and return to return. ''') 
    answer = await client.wait_for('message', check=lambda message: message.author == ctx.author and message != "") 
     # Gets user input and checks if message is not empty and was sent by the same user answer = answer.content