使用以下代码,我希望使其在结束之前循环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();
}
}
我想用这段代码做到这一点-
谢谢!
答案 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