gpt4 book ai didi

python - 无法连接到主机。 Heroku 和 Discord 机器人问题

转载 作者:行者123 更新时间:2023-12-04 17:23:23 24 4
gpt4 key购买 nike

我正在使用 wavelink 使用 python 制作一个不和谐的音乐机器人。当我第一次在我的电脑上启动这个应用程序时它工作正常,但昨天我想将它部署到 heroku 但它不工作,所以我试图再次运行它,只是在我的电脑上,使用相同的代码现在它根本不起作用。我认为代码与第一次完全相同,但每次运行机器人时都会出现:

WEBSOCKET | Connection Failure:: Cannot connect to host 127.0.0.1:2333ssl:default [Komputer zdalny odrzucił połączenie sieciowe] Traceback(most recent call last): File"C:\Python\lib\site-packages\aiohttp\connector.py", line 936, in_wrap_create_connectionreturn await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa File "C:\Python\lib\asyncio\base_events.py",line 1021, in create_connectionraise exceptions[0] File "C:\Python\lib\asyncio\base_events.py", line 1006, in create_connectionsock = await self._connect_sock( File "C:\Python\lib\asyncio\base_events.py", line 920, in _connect_sockawait self.sock_connect(sock, address) File "C:\Python\lib\asyncio\proactor_events.py", line 702, in sock_connectreturn await self._proactor.connect(sock, address) File "C:\Python\lib\asyncio\windows_events.py", line 808, in _pollvalue = callback(transferred, key, ov) File "C:\Python\lib\asyncio\windows_events.py", line 595, in finish_connectov.getresult() ConnectionRefusedError: [WinError 1225] Komputer zdalny odrzucił połączenie sieciowe

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File"C:\Python\lib\site-packages\wavelink\websocket.py", line 76, in_connectself._websocket = await self._node.session.ws_connect(uri, headers=self.headers, heartbeat=self._node.heartbeat) File"C:\Python\lib\site-packages\aiohttp\client.py", line 721, in_ws_connectresp = await self.request(method, url, File "C:\Python\lib\site-packages\aiohttp\client.py", line 480, in _requestconn = await self._connector.connect( File "C:\Python\lib\site-packages\aiohttp\connector.py", line 523, inconnectproto = await self._create_connection(req, traces, timeout) File "C:\Python\lib\site-packages\aiohttp\connector.py", line 858, in_create_connection_, proto = await self._create_direct_connection( File "C:\Python\lib\site-packages\aiohttp\connector.py", line 1004, in_create_direct_connectionraise last_exc File "C:\Python\lib\site-packages\aiohttp\connector.py", line 980, in_create_direct_connectiontransp, proto = await self._wrap_create_connection( File "C:\Python\lib\site-packages\aiohttp\connector.py", line 943, in_wrap_create_connectionraise client_error(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host127.0.0.1:2333 ssl:default [Komputer zdalny odrzucił połączenie sieciowe]

我认为问题在于这部分代码:

async def start_nodes(self):
await self.bot.wait_until_ready()

# Initiate our nodes. For this example we will use one server.
# Region should be a discord.py guild.region e.g sydney or us_central (Though this is not technically required)
await self.bot.wavelink.initiate_node(host='127.0.0.1',
port=2333,
rest_uri='http://127.0.0.1:2333',
password='youshallnotpass',
identifier='TEST',
region='europe')

文件 application.yml 看起来像这样:

server: # REST and WS server
port: 2333
address: 0.0.0.0
lavalink:
server:
password: "youshallnotpass"
sources:
youtube: true
bandcamp: true
soundcloud: true
twitch: true
vimeo: true
mixer: true
http: true
local: false
bufferDurationMs: 400
youtubePlaylistLoadLimit: 6 # Number of pages at 100 each
playerUpdateInterval: 5 # How frequently to send player updates to clients, in seconds
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
gc-warnings: true
#ratelimit:
#ipBlocks: ["1.0.0.0/8", "..."] # list of ip blocks
#excludedIps: ["...", "..."] # ips which should be explicit excluded from usage by lavalink
#strategy: "RotateOnBan" # RotateOnBan | LoadBalance | NanoSwitch | RotatingNanoSwitch
#searchTriggersFail: true # Whether a search 429 should trigger marking the ip as failing
#retryLimit: -1 # -1 = use default lavaplayer value | 0 = infinity | >0 = retry will happen this numbers times

metrics:
prometheus:
enabled: false
endpoint: /metrics

sentry:
dsn: ""
environment: ""
# tags:
# some_key: some_value
# another_key: another_value

logging:
file:
max-history: 30
max-size: 1GB
path: ./logs/

level:
root: INFO
lavalink: INFO

你有什么想法吗?

解决方案:好的,如果您遇到与我相同的问题并且您正在使用 Lavalink,则必须首先启动 Lavalink 服务器。在我的例子中,我必须在终端中输入“java -jar Lavalink.jar”来启动服务器。

最佳答案

我遇到了同样的问题,后来我想通了

你需要设置 Lavalink

  1. 下载OpenJDK 13.0.2然后提取
  2. 下载Lavalink
  3. 将第一步中的 Lavalink.jar 粘贴到 bin 中
mv ./Lavalink.jar ./open-jdk/bin
  1. 创建一个新文件 application.yml 并粘贴 this code
    - 确保将 address: 0.0.0.0 更改为 address: 127.0.0.1
server: # REST and WS server
port: 2333
address: 127.0.0.1
lavalink:
server:
password: "youshallnotpass"
sources:
youtube: true
bandcamp: true
soundcloud: true
twitch: true
vimeo: true
http: true
local: false
bufferDurationMs: 400
youtubePlaylistLoadLimit: 6 # Number of pages at 100 each
playerUpdateInterval: 5 # How frequently to send player updates to clients, in seconds
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
gc-warnings: true
#ratelimit:
#ipBlocks: ["1.0.0.0/8", "..."] # list of ip blocks
#excludedIps: ["...", "..."] # ips which should be explicit excluded from usage by lavalink
#strategy: "RotateOnBan" # RotateOnBan | LoadBalance | NanoSwitch | RotatingNanoSwitch
#searchTriggersFail: true # Whether a search 429 should trigger marking the ip as failing
#retryLimit: -1 # -1 = use default lavaplayer value | 0 = infinity | >0 = retry will happen this numbers times

metrics:
prometheus:
enabled: false
endpoint: /metrics

sentry:
dsn: ""
environment: ""
# tags:
# some_key: some_value
# another_key: another_value

logging:
file:
max-history: 30
max-size: 1GB
path: ./logs/

level:
root: INFO
lavalink: INFO
  1. 转到命令提示符并执行以下命令
pip install discord.py[voice] wavelink
  1. 打开解压 JDK 的文件夹,然后键入
java -jar Lavalink.jar

这将启动 lavalink 服务器,然后您就可以使用您的机器人了


如需更多帮助,请查看 this video

关于python - 无法连接到主机。 Heroku 和 Discord 机器人问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64941372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com