def on_member_join(self, member):
"""Automatically assign roles if guild has a role set through `newrole` command."""
if not member.guild.me.guild_permissions.manage_roles:
return
async with self.bot.db_pool.acquire() as con:
role_id = await con.fetchval('''
SELECT role_id FROM newrole WHERE guild_id = $1
''', member.guild.id)
if role_id is None:
return
role = discord.utils.get(member.guild.roles, id=role_id)
if role is None:
async with con.transaction():
await con.execute('''
DELETE FROM newrole WHERE guild_id = $1
''', member.guild.id)
return
await member.add_roles(role, reason='New Member')
评论列表
文章目录