async def on_member_join(self, member): """Called when a new member joins a guild.""" if not self.bot.is_ready(): return self.bot.cache.event_triggers["member_join"] += 1 # log event logging_channel_id = await self.bot.db.execute( "SELECT member_log_channel_id FROM logging_settings WHERE guild_id = %s", member.guild.id, one_value=True, ) if logging_channel_id: logging_channel = member.guild.get_channel(logging_channel_id) if logging_channel is not None: embed = discord.Embed(color=discord.Color.green()) embed.set_author(name=str(member), icon_url=member.avatar_url) await logging_channel.send(embed=embed) # welcome message greeter = await self.bot.db.execute( "SELECT channel_id, is_enabled, message_format FROM greeter_settings WHERE guild_id = %s", member.guild.id, one_row=True, ) if greeter: channel_id, is_enabled, message_format = greeter if is_enabled: greeter_channel = member.guild.get_channel(channel_id) if greeter_channel is not None: try: await greeter_channel.send( embed=util.create_welcome_embed( member, member.guild, message_format)) except discord.errors.Forbidden: pass # add autoroles roles = await self.bot.db.execute( "SELECT role_id FROM autorole WHERE guild_id = %s", member.guild.id, as_list=True) for role_id in roles: role = member.guild.get_role(role_id) if role is None: continue try: await member.add_roles(role) except discord.errors.Forbidden: pass
async def greeter_message(self, ctx, *, message): """ Change the greeter welcome message format. Use with "default" to reset to the default format. """ if message.lower() == "default": message = None await queries.update_setting(ctx, "greeter_settings", "message_format", message) preview = util.create_welcome_embed(ctx.author, ctx.guild, message) await ctx.send( f":white_check_mark: New welcome message format set:\n```{message}```Preview:", embed=preview, )
async def on_member_join(self, member): """Called when a new member joins a guild""" if not self.bot.is_ready(): return logging_channel_id = None logging_settings = self.bot.cache.logging_settings.get(str(member.guild.id)) if logging_settings: logging_channel_id = logging_settings.get("member_log_channel_id") if logging_channel_id: logging_channel = member.guild.get_channel(logging_channel_id) if logging_channel is not None: embed = discord.Embed(color=discord.Color.green()) embed.set_author(name=str(member), icon_url=member.display_avatar.url) try: await logging_channel.send(embed=embed) except discord.errors.Forbidden: pass # add autoroles roles = self.bot.cache.autoroles.get(str(member.guild.id), []) for role_id in roles: role = member.guild.get_role(role_id) if role is None: continue try: await member.add_roles(role) except discord.errors.Forbidden: pass # welcome message greeter = await self.bot.db.execute( "SELECT channel_id, is_enabled, message_format FROM greeter_settings WHERE guild_id = %s", member.guild.id, one_row=True, ) if greeter: channel_id, is_enabled, message_format = greeter if is_enabled: greeter_channel = member.guild.get_channel(channel_id) if greeter_channel is not None: try: await greeter_channel.send( embed=util.create_welcome_embed(member, member.guild, message_format) ) except discord.errors.Forbidden: pass