MCPcopy
hub / github.com/Rapptz/discord.py / request

Method request

discord/webhook/async_.py:130–239  ·  view source on GitHub ↗
(
        self,
        route: Route,
        session: aiohttp.ClientSession,
        *,
        payload: Optional[Dict[str, Any]] = None,
        multipart: Optional[List[Dict[str, Any]]] = None,
        proxy: Optional[str] = None,
        proxy_auth: Optional[aiohttp.BasicAuth] = None,
        files: Optional[Sequence[File]] = None,
        reason: Optional[str] = None,
        auth_token: Optional[str] = None,
        params: Optional[Dict[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

128 self._locks: weakref.WeakValueDictionary[Any, asyncio.Lock] = weakref.WeakValueDictionary()
129
130 async def request(
131 self,
132 route: Route,
133 session: aiohttp.ClientSession,
134 *,
135 payload: Optional[Dict[str, Any]] = None,
136 multipart: Optional[List[Dict[str, Any]]] = None,
137 proxy: Optional[str] = None,
138 proxy_auth: Optional[aiohttp.BasicAuth] = None,
139 files: Optional[Sequence[File]] = None,
140 reason: Optional[str] = None,
141 auth_token: Optional[str] = None,
142 params: Optional[Dict[str, Any]] = None,
143 ) -> Any:
144 headers: Dict[str, str] = {}
145 files = files or []
146 to_send: Optional[Union[str, aiohttp.FormData]] = None
147 bucket = (route.webhook_id, route.webhook_token)
148
149 try:
150 lock = self._locks[bucket]
151 except KeyError:
152 self._locks[bucket] = lock = asyncio.Lock()
153
154 if payload is not None:
155 headers['Content-Type'] = 'application/json'
156 to_send = utils._to_json(payload)
157
158 if auth_token is not None:
159 headers['Authorization'] = f'Bot {auth_token}'
160
161 if reason is not None:
162 headers['X-Audit-Log-Reason'] = urlquote(reason, safe='/ ')
163
164 response: Optional[aiohttp.ClientResponse] = None
165 data: Optional[Union[Dict[str, Any], str]] = None
166 method = route.method
167 url = route.url
168 webhook_id = route.webhook_id
169
170 async with AsyncDeferredLock(lock) as lock:
171 for attempt in range(5):
172 for file in files:
173 file.reset(seek=attempt)
174
175 if multipart:
176 form_data = aiohttp.FormData(quote_fields=False)
177 for p in multipart:
178 form_data.add_field(**p)
179 to_send = form_data
180
181 try:
182 async with session.request(
183 method, url, data=to_send, headers=headers, params=params, proxy=proxy, proxy_auth=proxy_auth
184 ) as response:
185 _log.debug(
186 'Webhook ID %s with %s %s has returned status code %s',
187 webhook_id,

Callers 14

delete_webhookMethod · 0.95
edit_webhookMethod · 0.95
execute_webhookMethod · 0.95
get_webhook_messageMethod · 0.95
edit_webhook_messageMethod · 0.95
fetch_webhookMethod · 0.95

Calls 10

AsyncDeferredLockClass · 0.85
json_or_textFunction · 0.85
HTTPExceptionClass · 0.85
ForbiddenClass · 0.85
NotFoundClass · 0.85
DiscordServerErrorClass · 0.85
add_fieldMethod · 0.80
resetMethod · 0.45
getMethod · 0.45
delay_byMethod · 0.45

Tested by

no test coverage detected