Browse Source

Fix application bot creation (fixes #387)

pull/10109/head
dolfies 3 years ago
parent
commit
1b7d6c8790
  1. 38
      discord/appinfo.py
  2. 7
      discord/http.py

38
discord/appinfo.py

@ -707,33 +707,47 @@ class Application(PartialApplication):
data = await self._state.http.reset_secret(self.id)
return data['secret'] # type: ignore # Usually not there
async def create_bot(self) -> ApplicationBot:
async def fetch_bot(self) -> ApplicationBot:
"""|coro|
Creates a bot attached to this application.
Fetches the bot attached to this application.
Raises
------
Forbidden
You do not have permissions to create bots.
You do not have permissions to fetch the bot,
or the application does not have a bot.
HTTPException
Creating the bot failed.
Fetching the bot failed.
Returns
-------
:class:`ApplicationBot`
The newly created bot.
The bot attached to this application.
"""
state = self._state
data = await state.http.botify_app(self.id)
data['public'] = self.public
data['require_code_grant'] = self.require_code_grant
data = await self._state.http.edit_bot(self.id, {})
data['public'] = self.public # type: ignore
data['require_code_grant'] = self.require_code_grant # type: ignore
bot = ApplicationBot(data=data, state=state, application=self)
self.bot = bot
self.bot = bot = ApplicationBot(data=data, state=self._state, application=self)
return bot
async def create_bot(self) -> None:
"""|coro|
Creates a bot attached to this application.
This does not fetch or cache the bot.
Raises
------
Forbidden
You do not have permissions to create bots.
HTTPException
Creating the bot failed.
"""
await self._state.http.botify_app(self.id)
class InteractionApplication(Hashable):
"""Represents a very partial Application received in interaction contexts.

7
discord/http.py

@ -2326,9 +2326,14 @@ class HTTPClient:
super_properties_to_track=True,
)
def botify_app(self, app_id: Snowflake):
def botify_app(self, app_id: Snowflake) -> Response[None]:
return self.request(Route('POST', '/applications/{app_id}/bot', app_id=app_id), super_properties_to_track=True)
def edit_bot(self, app_id: Snowflake, payload: dict) -> Response[user.User]:
return self.request(
Route('PATCH', '/applications/{app_id}/bot', app_id=app_id), json=payload, super_properties_to_track=True
)
def reset_secret(self, app_id: Snowflake) -> Response[appinfo.AppInfo]:
return self.request(Route('POST', '/applications/{app_id}/reset', app_id=app_id), super_properties_to_track=True)

Loading…
Cancel
Save