title: Discord bot which ping minecraft server. Python
body: <p>I want to make discord bot which ping the minecraft server and: if server respond he edit
  lock voice channel name to &quot;Server Status - Online&quot;. Else he edit channel name: &quot;Server Status - Offline&quot;
  <strong>I'm use mcstatus to ping the server and this work!</strong>
  But sometimes bot have lags and i don't know how fix it.
  P.s. Sorry for my bad english.</p>
  <pre><code>from mcstatus import MinecraftServer
  import discord
  from discord.ext import commands
  import time
  
  TOKEN = &quot;token here&quot;
  
  client = discord.Client()
  
  @client.event
  
  async def on_ready():
      print(&quot;Bot Connected&quot;)
      await client.wait_until_ready()
      channel = client.get_channel(id)
      while True:
          time.sleep(30)
          try:
              server = MinecraftServer.lookup(&quot;26.51.174.109:25565&quot;)
              status = server.status()
              await channel.edit(name = &quot;Server Status - Online&quot;)
          except:
              await channel.edit(name = &quot;Server Status - Offline&quot;)
  client.run( TOKEN )
  </code></pre>
  <p>UPD:
  I rewrite the code, but problem not lost.</p>
  <pre><code>import discord
  import asyncio
  import time
  import socket
  TOKEN = &quot;token&quot;
  
  client = discord.Client()
  
  @client.event
  
  async def on_ready():
      print(&quot;Bot Connected&quot;)
      await client.wait_until_ready()
      channel = client.get_channel(id)            
      def ping(ip, port):
          try:
              s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              s.connect((ip, int(port)))
              return True
          except:
              return False
      while True:
          online = ping(&quot;26.51.174.109&quot;, &quot;25565&quot;)
          if online == True:
              print(&quot;server online&quot;)
              await channel.edit(name = &quot;Server Status - Online&quot;)
          else:
              print(&quot;server offline&quot;)
              await channel.edit(name = &quot;Server Status - Offline&quot;)
          await asyncio.sleep(5)
  client.run( TOKEN )
  </code></pre>