Skip to content

Commit 00c0f13

Browse files
provide an invite link if the bot isn't in the configured guild
1 parent 333625c commit 00c0f13

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

botstrap.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ 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+
response = self.get(f"/guilds/{self.guild_id}")
121+
except HTTPStatusError:
122+
return False
123+
return response.status_code == 200
124+
117125
def upgrade_server_to_community_if_necessary(
118126
self,
119127
rules_channel_id_: int | str,
@@ -210,6 +218,17 @@ def create_webhook(self, name: str, channel_id_: int) -> str:
210218
if discord_client.upgrade_application_flags_if_necessary():
211219
log.info("Application flags upgraded successfully, and necessary intents are now enabled.")
212220

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

215234
all_roles = discord_client.get_all_roles()

0 commit comments

Comments
 (0)