gsd 2 years ago
parent
commit
6a62b1f8fa
  1. 16
      other_ext/register.py

16
other_ext/register.py

@ -39,7 +39,7 @@ class Extension:
if not result:
return await interaction.followup.send('Кароч нельзя привязать профиль(((', ephemeral=True)
await self.final_stage(interaction.user)
await self.final_stage(interaction.user, interaction.guild)
return await interaction.followup.send(f'Ты крут!', ephemeral=True)
@core.tree.command(name = "unregister", description = "Отвязать профиль")
@ -52,17 +52,17 @@ class Extension:
player = await core.GetPlayer(steam64, steam64, False)
await player.RemoveDiscordId(interaction.user.id)
await interaction.followup.send(f'Профиль отвязан, друг', ephemeral=True)
await self.remove_role(interaction.user.id)
await self.remove_role(interaction.user.id, interaction.guild)
return
@core.event
async def on_member_join(member):
async def on_member_join(member: discord.Member):
if member.guild.id != core.main_server_id:
return
try:
await core.GetSteam64OfDiscord(member, True)
await self.final_stage(member)
await self.final_stage(member, member.guild)
return
except:
pass
@ -96,14 +96,14 @@ class Extension:
print(f"Cannot delete message from auth channel, error: {err}")
return
async def final_stage(self, user: discord.Member):
async def final_stage(self, user: discord.Member, guild: discord.Guild):
try:
await user.add_roles(discord.Role(id=self.default_role))
await user.add_roles(guild.get_role(self.default_role))
except Exception as err:
print(f"Cannot set role({self.default_role}) to {user}, error: {err}")
async def remove_role(self, user: discord.Member):
async def remove_role(self, user: discord.Member, guild: discord.Guild):
try:
await user.remove_roles(discord.Role(id=self.default_role))
await user.remove_roles(guild.get_role(self.default_role))
except Exception as err:
print(f"Cannot remove role({self.default_role}) from {user}, error: {err}")
Loading…
Cancel
Save