Skip to content

Commit b488508

Browse files
provide an invite link if the bot isn't in the configured guild
1 parent b787bc1 commit b488508

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

botstrap.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ def upgrade_application_flags_if_necessary(self) -> bool:
114114

115115
return False
116116

117+
def check_if_in_guild(self) -> bool:
118+
"""Check if the bot is a member of the guild."""
119+
try:
120+
_ = self.get(f"/guilds/{self.guild_id}")
121+
except HTTPStatusError as e:
122+
if e.response.status_code == 403 or e.response.status_code == 404:
123+
return False
124+
raise
125+
return True
126+
117127
def upgrade_server_to_community_if_necessary(
118128
self,
119129
rules_channel_id_: int | str,
@@ -210,6 +220,17 @@ def create_webhook(self, name: str, channel_id_: int) -> str:
210220
if discord_client.upgrade_application_flags_if_necessary():
211221
log.info("Application flags upgraded successfully, and necessary intents are now enabled.")
212222

223+
if not discord_client.check_if_in_guild():
224+
client_id = discord_client.app_info["id"]
225+
log.error("The bot is not a member of the configured guild with ID %s.", GUILD_ID)
226+
log.warning(
227+
"Please invite with the following URL and rerun this script: "
228+
"https://discord.com/oauth2/authorize?client_id=%s&guild_id=%s&scope=bot+applications.commands&permissions=8",
229+
client_id,
230+
GUILD_ID,
231+
)
232+
sys.exit(69)
233+
213234
config_str = "#Roles\n"
214235

215236
all_roles = discord_client.get_all_roles()

0 commit comments

Comments
 (0)