Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add agree_guild_rules guild method #664

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -5332,3 +5332,21 @@ async def directory_broadcast_eligibility(self) -> bool:
"""
data = await self._state.http.get_directory_broadcast_info(self.id, 1)
return data['can_broadcast']

async def agree_guild_rules(self, url: str | Invite):
resolved = utils.resolve_invite(url)

data = await self._state.http.get_invite(
resolved.code,
with_counts=True,
input_value=resolved.code if isinstance(url, Invite) else url,
)
if isinstance(url, Invite):
invite = url
else:
invite = Invite.from_incomplete(state=self._state, data=data)

rules_form = await self._state.http.get_guild_rules_form(self.id, invite.id)
if not rules_form.get('form_fields'):
return
await self._state.http.agree_guild_rules(self.id, rules_form)
16 changes: 16 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -4685,3 +4685,19 @@ def join_hub(self, email: str, guild_id: Snowflake, code: str) -> Response[hub.E
def join_hub_token(self, token: str) -> Response[hub.EmailDomainVerification]:
payload = {'token': token}
return self.request(Route('POST', '/guilds/automations/email-domain-lookup/verify'), json=payload)

async def get_guild_rules_form(self, guild_id: Snowflake, invite_id: str):
params = {
"with_guild": "false",
"invite_code": invite_id,
}
return await self.request(Route('GET', '/guilds/{guild_id}/member-verification', guild_id=guild_id), params=params)

async def agree_guild_rules(self, guild_id: Snowflake, rules_form: dict):
form_fields = rules_form["form_fields"][0].copy()
form_fields["response"] = True
payload = {
"version": rules_form["version"],
"form_fields": [form_fields],
}
return await self.request(Route('PUT', '/guilds/{guild_id}/requests/@me', guild_id=guild_id), json=payload)