Added logic to handle bot being unable to change a nickname due to role hierarchy.
This commit is contained in:
@@ -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:
|
||||||
await user.edit(nick=self.new_nickname)
|
try:
|
||||||
content = interaction.message.content + f" Approved by <@{interaction.user.id}>."
|
await user.edit(nick=self.new_nickname)
|
||||||
await interaction.response.edit_message(content=content, view=None)
|
content = interaction.message.content + f"\nApproved by <@{interaction.user.id}>."
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user