pycord icon indicating copy to clipboard operation
pycord copied to clipboard

proxy works for ctx.send, but not works for ctx.respond

Open xwzp opened this issue 4 years ago • 1 comments

Summary

Bot.client(proxy="xx") not works for ctx.respond

Reproduction Steps

I ran my code in a limited network, unless it passes through proxy or discord api requests will be blocked Code as follows, only ctx.send passed through proxy

bot = discord.Bot(
    # trust_env=True,
    proxy="http://localhost:9999",
)

@bot.slash_command(guild_ids=["my guild id"])
async def hello2(ctx):
    """Say hello to the bot"""  # the command description can be supplied as the docstring
    await ctx.send(f"Hello {ctx.author}!")
    await ctx.respond(f"Hello {ctx.author}!")

image

Minimal Reproducible Code

No response

Expected Results

all ctx.send he ctx.respond pass network request through proxy

Actual Results

only ctx.send passed through proxy

Intents

discord.Intents.default()

System Information

  • Python v3.10.1-final
  • py-cord v2.0.0-alpha
    • py-cord pkg_resources: v2.0.0a4738+g99e2312f
  • aiohttp v3.7.4.post0
  • system info: Darwin 20.6.0 Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:07 PST 2021; root:xnu-7195.141.14~1/RELEASE_X86_64

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Addtional Content

I had looked at the source, the reason is ctx.respond uses AsyncWebhookAdapter.request to send api.

here are codes of AsyncWebhookAdapter.request, I found session.request don't use proxy

class AsyncWebhookAdapter:
    def __init__(self):
        self._locks: weakref.WeakValueDictionary = weakref.WeakValueDictionary()

    async def request(...):
        ...
        async with session.request(method, url, data=to_send, headers=headers, params=params) as response:
              ....

No response

xwzp avatar Jan 04 '22 08:01 xwzp

Proxies don't seem to be supported by the webhook adapter, I'm updating this issue to be a feature request.

Dorukyum avatar Feb 01 '22 09:02 Dorukyum