Added logic to handle bot being unable to change a nickname due to role hierarchy.

This commit is contained in:
2023-07-29 21:08:16 -04:00
parent 271cf14697
commit fa3fc6bd75
+13 -2
View File
@@ -62,9 +62,20 @@ class UsernameRequest(nextcord.ui.View):
async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
user = interaction.guild.get_member(self.user_id) user = interaction.guild.get_member(self.user_id)
if user is not None: if user is not None:
try:
await user.edit(nick=self.new_nickname) await user.edit(nick=self.new_nickname)
content = interaction.message.content + f" Approved by <@{interaction.user.id}>." content = interaction.message.content + f"\nApproved by <@{interaction.user.id}>."
await interaction.response.edit_message(content=content, view=None) await interaction.response.edit_message(content=content, view=None)
except nextcord.errors.Forbidden:
await interaction.response.send_message(
content="Please change manually.",
ephemeral=True,
)
content = (
interaction.message.content
+ "\n\nFailed. User has too high permissions for bot to change nickname."
)
await interaction.followup.edit_message(interaction.message.id, content=content, view=None)
else: else:
await interaction.response.edit_message( await interaction.response.edit_message(
content="An error occured while changing the user's nickname.", view=None content="An error occured while changing the user's nickname.", view=None
@@ -72,5 +83,5 @@ class UsernameRequest(nextcord.ui.View):
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red) @nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red)
async def deny(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): async def deny(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
content = interaction.message.content + f" Denied by <@{interaction.user.id}.>" content = interaction.message.content + f"\nDenied by <@{interaction.user.id}.>"
await interaction.response.edit_message(content=content, view=None) await interaction.response.edit_message(content=content, view=None)