title: How to make discord bot disconnect from voice channel after playing?
body: <p>I'm trying to get the discord bot to disconnect from the voice channel after it finishes playing, but I can't use &quot;await&quot; in a lambda expression.</p>
  <p>I tried it:</p>
  <pre class="lang-py prettyprint-override"><code>voice_client.play(source=audio_source, after=lambda _: await voice_client.disconnect())
  </code></pre>
  <p>But the result is:</p>
  <pre><code>SyntaxError: 'await' outside async function
  </code></pre>
  <p>I tried it:</p>
  <pre class="lang-py prettyprint-override"><code>voice_client.play(source=audio_source, after=lambda _: voice_client.disconnect())
  </code></pre>
  <p>But the result is:</p>
  <pre><code>RuntimeWarning: coroutine 'VoiceClient.disconnect' was never awaited self.after(error)
  </code></pre>
  <p>I tried it:</p>
  <pre class="lang-py prettyprint-override"><code>voice_client.play(source=audio_source, after=voice_client.disconnect)
  </code></pre>
  <p>But the result is:</p>
  <pre><code>TypeError: disconnect() takes 1 positional argument but 2 were given
  </code></pre>
  <p>My solution:</p>
  <pre class="lang-py prettyprint-override"><code>voice_client.play(
      source=audio_source,
      after=lambda _: asyncio.run_coroutine_threadsafe(
          coro=voice_client.disconnect(),
          loop=voice_client.loop
      ).result()
  )
  </code></pre>