# Discord Bot-part2 迴圈應用時間 - discord狀態 *** ![](https://i.imgur.com/cxWE2uh.jpg) ```python= @bot.event async def on_ready(): ``` ```python= stateList = ["請問您今天要來點兔子嗎?","請問您今天要來點兔子嗎??","請問您今天要來點兔子嗎?~BLOOM~","請問您今天要來點兔子嗎?? 〜Sing For You〜","請問您今天要來點兔子嗎?? 〜Dear My Sister〜"] index = 0 while True: if index > len(stateList): index = 0 await asyncio.sleep(30) activeName = stateList[index] activity = discord.Activity(type = discord.ActivityType.watching, name = activeName) status = discord.Status.idle await bot.change_presence(status = status, activity = activity) index += 1 ``` 翻譯 > 第一行 stateList 為一個變數,裡面放你要的狀態 > 第二行是為讀取 stateList 裡元素(第幾個,list從零開始)而設的變數 > 第三行是無限迴圈,讓他一直跑 > 第四+五行是判斷index是否大於list中的元素量(不然就找不到東西了><) > 第六行的寫法是每30秒執行一次 > 第七行是把activeName設為stateList的元素 > 第八行是設定文字 > 第九行是設定狀態 > 第十行是讓機器人加上狀態 > 最後就是下一個元素,不然就不會變啦 註: > 第八行的 type(discord.Activity的參數) 可以是 > 1. playing(遊玩中)、 > 2. streaming(直撥中)、 > 3. listening(聆聽中)、 > 4. watching(觀看中)、 > 5. custom(自定義) > 第九行的 status > discord.Status.<狀態>, > <狀態>可以是 > 1. online(上線), > 2. offline(下線), > 3. idle(閒置), > 4. dnd(請勿打擾), > 5. invisible(隱身) ###### tags: `Python` `DiscordBot`