为什么只有四次便便?

Why it inly loops 4 times?

为什么我的命令只循环 4 次,但我将 x 设置为 100 次而不是 4 次。谁能帮我解决这个问题!我不明白这个错误,我需要在星期五之前修复它

import discord
from discord.ext import commands, tasks
import asyncio
import keyboard
import time
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller
from pynput.keyboard import Controller
from pynput import mouse
import mouse

TOKEN = 'mytoken...'

client = commands.Bot(command_prefix = '.')

@client.command(name='play')
async def play(ctx):

    await ctx.channel.send("Hello! welcome to a game where you play my game through discord messages! How yo play: if you want to go write - 'go', left - 'left', right - 'right', back - 'back', sprint 'lgo', click - 'click', jump - 'jump'")

    
    
    x = '100'
    for x in 'play':


        
        msg = await client.wait_for('message')
        response = (msg.content)
        print(response)
    
    
        if response == "go":

            
            keyboard.press('w')
            time.sleep(2)
            keyboard.release('w')
    
        if  response == "left":   
            
            keyboard.press('a')
            time.sleep(2)
            keyboard.release('a')
        
        if response == "right":

            
            keyboard.press('d')
            time.sleep(2)
            keyboard.release('d')
    
        if  response == "back":   
            
            keyboard.press('s')
            time.sleep(2)
            keyboard.release('s')
        
        if response == "jump":

            
            keyboard.press('b')
            keyboard.release('b')
    
        if  response == "click":   
            
            mouse.click('left')
        
        if response == "lgo":

            
            keyboard.press('shift + w')
            time.sleep(5)
            keyboard.release('w')

            

client.run(TOKEN)

我正在制作一个 discord 机器人,它可以通过 discord 消息玩我的游戏,但我有一个奇怪的错误软件,它循环 4 次而不是 100 次,因为它需要做的

它只循环了 4 次,因为你正在遍历字符串 play

x = '100' 
for x in 'play':
  print(x)

这个输出:

p
l
a
y

(并完全忽略 100,因为它在循环中被覆盖)

要循环 100 次,请使用:

x = 100 # number, not string
for i in range(x):
  print(i)

这个输出:

0
1
2
3
...
98
99

x保持值100

使用:

for x in range(1, 100):

而不是:

 x = '100'
    for x in 'play'