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

Method request

discord/http.py:589–795  ·  view source on GitHub ↗
(
        self,
        route: Route,
        *,
        files: Optional[Sequence[File]] = None,
        form: Optional[Iterable[Dict[str, Any]]] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

587 return value
588
589 async def request(
590 self,
591 route: Route,
592 *,
593 files: Optional[Sequence[File]] = None,
594 form: Optional[Iterable[Dict[str, Any]]] = None,
595 **kwargs: Any,
596 ) -> Any:
597 method = route.method
598 url = route.url
599 route_key = route.key
600
601 bucket_hash = None
602 try:
603 bucket_hash = self._bucket_hashes[route_key]
604 except KeyError:
605 key = f'{route_key}:{route.major_parameters}'
606 else:
607 key = f'{bucket_hash}:{route.major_parameters}'
608
609 ratelimit = self.get_ratelimit(key)
610
611 # header creation
612 headers: Dict[str, str] = {
613 'User-Agent': self.user_agent,
614 }
615
616 if self.token is not None:
617 headers['Authorization'] = 'Bot ' + self.token
618 # some checking if it's a JSON request
619 if 'json' in kwargs:
620 headers['Content-Type'] = 'application/json'
621 kwargs['data'] = utils._to_json(kwargs.pop('json'))
622
623 try:
624 reason = kwargs.pop('reason')
625 except KeyError:
626 pass
627 else:
628 if reason:
629 headers['X-Audit-Log-Reason'] = _uriquote(reason, safe='/ ')
630
631 kwargs['headers'] = headers
632
633 # Proxy support
634 if self.proxy is not None:
635 kwargs['proxy'] = self.proxy
636 if self.proxy_auth is not None:
637 kwargs['proxy_auth'] = self.proxy_auth
638
639 if not self._global_over.is_set():
640 # wait until the global lock is complete
641 await self._global_over.wait()
642
643 response: Optional[aiohttp.ClientResponse] = None
644 data: Optional[Union[Dict[str, Any], str]] = None
645 async with ratelimit:
646 for tries in range(5):

Callers 15

static_loginMethod · 0.95
logoutMethod · 0.95
start_groupMethod · 0.95
leave_groupMethod · 0.95
start_private_messageMethod · 0.95
send_messageMethod · 0.95
send_typingMethod · 0.95
delete_messageMethod · 0.95
delete_messagesMethod · 0.95
edit_messageMethod · 0.95
add_reactionMethod · 0.95
remove_reactionMethod · 0.95

Calls 14

get_ratelimitMethod · 0.95
json_or_textFunction · 0.85
HTTPExceptionClass · 0.85
RateLimitedClass · 0.85
ForbiddenClass · 0.85
NotFoundClass · 0.85
DiscordServerErrorClass · 0.85
popMethod · 0.80
add_fieldMethod · 0.80
waitMethod · 0.45
resetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected