回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在用python创建一个Discord bot,当我的bot尝试连接lavalink时,我遇到了一个错误。我对bot和lavalink使用Docker compose,我的lavalink客户端是wavelink。我已经检查了lavalink是否在正确的端口上</p>
<p>有人知道怎么了吗</p>
<p>我的<code>docker-compose.yml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>version: "3.9"
services:
bot:
build:
context: .
dockerfile: Dockerfile
restart: on-failure
depends_on:
lavalink:
condition: service_started
lavalink:
container_name: lavalink
image: fredboat/lavalink:master
volumes:
- ./Lavalink/application.yml:/opt/Lavalink/application.yml
ports:
- 2333
restart: always
</code></pre>
<p>我的<code>music.py</code></p>
<pre><code>class Music(commands.Cog, wavelink.WavelinkMixin, name="music"):
def __init__(self, client):
self.client = client
self.fancy_name = "Music"
if not hasattr(client, 'wavelink'):
self.client.wavelink = wavelink.Client(bot=self.client)
self.client.loop.create_task(self.start_nodes())
async def start_nodes(self):
await self.client.wait_until_ready()
await self.client.wavelink.initiate_node(host='127.0.0.1',
port=2333,
rest_uri='http://127.0.0.1:2333',
password="pass",
identifier='MAIN',
region='us_central')
</code></pre>
<p>我的错误是:</p>
<pre class="lang-none prettyprint-override"><code> Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/wavelink/websocket.py", line 76, in _connect
self._websocket = await self._node.session.ws_connect(uri, headers=self.headers, heartbeat=self._node.heartbeat)
File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 721, in _ws_connect
resp = await self.request(method, url,
File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 480, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 858, in _create_connection
_, proto = await self._create_direct_connection(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 980, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 943, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 127.0.0.1:2333 ssl:default [Connect call failed ('127.0.0.1', 2333)]
</code></pre>