Skip to content

Commit a71898d

Browse files
committed
Refactor bot.py
1 parent 095d804 commit a71898d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

discord/bot.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async def register_commands(self) -> None:
199199
to_update = update_guild_commands[guild_id]
200200
update_guild_commands[guild_id] = to_update + [as_dict]
201201

202-
for guild_id in update_guild_commands:
202+
for guild_id, guild_data in update_guild_commands.items():
203203
try:
204204
cmds = await self.http.bulk_upsert_guild_commands(
205205
self.user.id, guild_id, update_guild_commands[guild_id]
@@ -208,11 +208,10 @@ async def register_commands(self) -> None:
208208
# Permissions for this Guild
209209
guild_permissions: List = []
210210
except Forbidden:
211-
if not update_guild_commands[guild_id]:
211+
if not guild_data:
212212
continue
213-
else:
214-
print(f"Failed to add command to guild {guild_id}", file=sys.stderr)
215-
raise
213+
print(f"Failed to add command to guild {guild_id}", file=sys.stderr)
214+
raise
216215
else:
217216
for i in cmds:
218217
cmd = get(
@@ -261,16 +260,14 @@ async def register_commands(self) -> None:
261260
for permission in item["permissions"]:
262261
if isinstance(permission["id"], str):
263262
# Replace Role Names
264-
if permission["type"] == 1 and isinstance(
265-
permission["id"], str
266-
):
263+
if permission["type"] == 1:
267264
role = get(
268265
self.get_guild(guild_id).roles,
269266
name=permission["id"],
270267
)
271268

272269
# If not missing
273-
if not role is None:
270+
if role is not None:
274271
new_cmd_perm["permissions"].append(
275272
{
276273
"id": role.id,
@@ -284,7 +281,7 @@ async def register_commands(self) -> None:
284281
guild_id=guild_id, role=permission["id"]
285282
)
286283
)
287-
# Add Owner IDs
284+
# Add owner IDs
288285
elif (
289286
permission["type"] == 2 and permission["id"] == "owner"
290287
):
@@ -306,7 +303,7 @@ async def register_commands(self) -> None:
306303
"permission": permission["permission"],
307304
}
308305
)
309-
# Add the Rest
306+
# Add the rest
310307
else:
311308
new_cmd_perm["permissions"].append(permission)
312309

@@ -647,7 +644,7 @@ def remove_check(self, func, *, call_once: bool = False) -> None:
647644

648645
try:
649646
l.remove(func)
650-
except ValueError:
647+
except guild_dataError:
651648
pass
652649

653650
def check_once(self, func):

0 commit comments

Comments
 (0)