【问题标题】:How to use discord python bot with proxy?如何使用带代理的不和谐 python 机器人?
【发布时间】:2019-08-16 17:30:52
【问题描述】:

需要使用带有代理(https 或 socks)的不和谐机器人。 例如,代理是:192.168.1.1:3125,代理授权是:proxy_login:proxy_pass

我已经尝试过这个例子:how to connect a discord bot through proxy 但它不能。

client = discord.Client(proxy=USER_PROXY, proxy_auth=aiohttp.BasicAuth(USER_PROXY_LOGIN, USER_PROXY_PASS))

【问题讨论】:

    标签: python proxy discord discord.py


    【解决方案1】:

    您需要创建一个aiohttp.ProxyConnector 并将其作为connector 传递给您的Client

    from aiohttp import ProxyConnector, BasicAuth
    
    basic_auth = BasicAuth(USER_PROXY_LOGIN, USER_PROXY_PASS)
    connector = ProxyConnector(USER_PROXY, proxy_auth=basic_auth)
    
    cient = discord.Client(connector=connector)
    

    正如您链接的问题,discord.py 不支持 HTTP 代理,仅支持 HTTPS 代理。

    【讨论】:

    • 在 aiohttp 中此代码:def update_proxy(self, proxy, proxy_auth): if proxy and not proxy.startswith('http://'): raise ValueError("Only http proxies are supported") if proxy_auth and not isinstance(proxy_auth, helpers.BasicAuth): raise ValueError("proxy_auth must be None or BasicAuth() tuple") self.proxy = proxy self.proxy_auth = proxy_auth 所以它不适用于 https?
    • @СергейЖиренкин 你使用的是什么版本的 discord.py 和 aiohttp?
    • discord - 0.16.12 aiohttp - 1.0.5 python 3.6
    【解决方案2】:

    对于最新版本 1.7.3,Client 类的构造函数上有一个 proxy 参数

    你只需要:

    client = discord.Client(proxy="http://localhost:7890")
    

    https://discordpy.readthedocs.io/en/stable/api.html#client

    【讨论】:

      猜你喜欢
      • 2021-05-24
      • 2021-10-30
      • 2021-05-27
      • 2021-07-15
      • 1970-01-01
      • 2021-12-21
      • 2021-03-29
      • 2021-07-11
      • 2021-03-25
      相关资源
      最近更新 更多